判断回文数

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";
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值