求回文数

题目出处:桂电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.

posted @ 2013-12-19 08:39  ediszhao  阅读(409)  评论(0编辑  收藏  举报