求回文数

题目出处:桂电oj,网址:http://onlinejudge.guet.edu.cn/guetoj/problem/view/1029.html

Description

给你一个数字,你要判断它是不是回文数字。例如134431或者242这种左右对称的数就叫做回文数。
现在你需要编写一个程序判断输入的数字是否为回文数。你需要判断输入的n是不是回文数字,如果是,请返回1,否则请返回0

Input

输入要判断的数,其中数的长度是未知的。

Output

是回文数输出1,否则输出0

Sample Input

123
12321

Sample Output

0
1

#include <iostream>
#include <cstring>
using namespace std;
int Is_huiwenshu(char a[1024]);
int main()
{
    char x[1024] = {0};
    cin >> x;
    cout << Is_huiwenshu(x) << endl;
    return 0;
}
int Is_huiwenshu(char a[1024])
{
    char b[1024] = {0};
    int i= 0;
    int len = strlen(a);
    int len1 = len;
    while ( len > -1 )
    {
        b[len-1] = a[i];
        i++;
        len--;
    }
    for (int j = 0;j < len1;)
    {
        if (a[j] == b[j])
        {
             j++;
             if (a[j] == '\0' &&b[j] == '\0')
             {
                 return 1;
             }
        }
        else
            return 0;
    }
}

This is what I think,

if you got a better idea, could you please send an E-mail to ediszhao@sina.com for my to learn.

转载于:https://www.cnblogs.com/ediszhao/p/3481421.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值