Enter an integer from the keyboard to judge whether the number is palindrome number. If it is a palindrome, "yes!" is output; otherwise, "no!" is output. The so-called palindrome number is that reading from left to right is the same number as reading from right to left. For example, 788723432 is the palindrome number.
从键盘上输入一个整数,判断该数是否为回文数。如果是回文则输出“Yes!”,否则输出“No!”。所谓回文数就是从左向右读与从右向左读都是一样的数。比如7887,23432是回文数。
Input Format 输入格式:
输入一个整数
Output Format 输出格式:
输出Yes!或者No!
Sample Input输入样例:
在这里给出一组输入。例如:
7887
Yes!
在这里给出相应的输出。例如:#include <iostream>
using namespace std;
int main()
{
int i=0,x,t1,t2=0;
char t[10];
cin>>x;
while(x)
{
i++;
t1=x%10;
t[t2]=(char)t1;
x=x/10;
t2++;
}
char *p_start,*p_end;
p_start=&t[0];
p_end=&t[0]+i-1;
bool flags = false;
if(i%2==0)
{
for(int k =1;k<=i/2;k++)
{
if(*p_start==*p_end)
{
flags=true;
}
else
{
flags=false;
break;
}
p_start++;
p_end--;
}
}
else
{
for(int k =1;k<=i/2;k++)
{
if(*p_start==*p_end)
{
flags=true;
}
else
{
flags=false;
break;
}
p_start++;
p_end--;
}
}
if(flags)
cout<<"Yes";
else
cout<<"No";
}