I. Reversion Count
Description:
There is a positive integer X, X's reversion count is Y. For example, X=123, Y=321; X=1234, Y=4321. Z=(X-Y)/9, Judge if Z is made up of only one number(0,1,2...9), like Z=11,Z=111,Z=222,don't consider '+'and '-'.
Input:
Input contains of several test cases. Each test case only contains of a number X, L is the length of X. ( 2 <= L < 100)
Output:
Output “YES”or “NO”.
样例输入
10 13
样例输出
YES YES
思路:
除第一位和最后一位外,是回文则输出"YES",否则,输出"NO"。
代码:
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int t;
int n;
char s[105];
while(cin>>s)
{
n=strlen(s);
if(n<=3)
cout<<"YES"<<endl;
else
{
int flag=0;
int i=1;
int j=n-2;
while(i<=j)
{
if(s[i]-'0'==s[j]-'0')
{
i++;
j--;
}
else
{
flag=1;
break;
}
}
if(flag==1)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
}
return 0;
}