判断十进制数字是否首尾对称,用的是无符号整数,范围比int大
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define N 10100
int a[N];
int num;
void save(unsigned int n){
if(n < 10)
{
a[num] = n;
return ;
}
a[num++] = n%10;
save(n/10);
}
int judge(int st,int en){
if(st == en || st - en == 1)
return 1;
if(a[st] != a[en])
return 0;
else
judge(st+1,en-1);
}
int main(){
unsigned int n;
while(cin>>n){
num = 0;
memset(a,0,sizeof(a));
save(n);
if(judge(0,num))
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}