题目描述
在超市里,有一些价格标签倒置后,数字竟不会发生改变。转置 180 度后不变的十进制数字被称为中心对称数(Strobogrammatic Numbers)。下图分别给出$0$到$9$这十个数字倒置后的样子:
中心对称数是指沿中心旋转 180 度后不变的十进制正整数。
- 0,1,8 旋转后不变;
- 6 旋转后为 9,9 旋转后为 6;
- 其他数字旋转后不能构成合理的数字。
给定一个正整数 $s$,请判断 $s$ 是否是中心对称数。注意有一部分输入将会非常大。
输入描述
单个整数:表示 $s$。
数据范围
记 $s$ 的十进制长度为 $n$,
- 对于 50% 的数据,1≤n≤10;
- 对于 100% 的数据,1≤n≤10000。
输出描述
- 如果输入的数字是中心对称数,输出
Strobogrammatic number
, - 否则输出
Not a strobogrammatic number
。
输入样例
18081
输出样例
Strobogrammatic number
#include<bits/stdc++.h>
using namespace std;
string a;
char b[10];
int main()
{
cin>>a;
b[1]='1';
b[8]='8';
b[0]='0';
b[6]='9';
b[9]='6';
int i,n=a.size();
for(i=0;i<n;i++)
{
if(a[i]=='2'||a[i]=='3'||a[i]=='4'||a[i]=='5'||a[i]=='7')
{
printf("Not a strobogrammatic number");
return 0;
}
else if(!(a[i]==b[a[n-i-1]-'0']))
{
printf("Not a strobogrammatic number");
return 0;
}
}
printf("Strobogrammatic number");
return 0;
}