zoukankan      html  css  js  c++  java
  • 求回文数

    题目出处:桂电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] == '' &&b[j] == '')
                 {
                     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.

  • 相关阅读:
    The Best Seat in ACM Contest
    确定比赛名次
    Red and Black
    Can you find it?
    胜利大逃亡
    Reward
    DXUT编译指南(转)
    逐顶点和逐像素光照
    转战DX
    hlsl之ambient
  • 原文地址:https://www.cnblogs.com/ediszhao/p/3481421.html
Copyright © 2011-2022 走看看