回文数猜想

....理工上用了 long long 才过 .....

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<vector>
 8 #include<set>
 9 #include<stack>
10 #include<string>
11 #include<sstream>
12 #include<map>
13 #include<cctype>
14 #include<limits.h>
15 using namespace std;
16 __int64 FINTE(__int64 Integer)
17 {
18     __int64 Finteger=0;
19     while(Integer!=0)
20     {
21         Finteger+=Integer%10;
22         Integer=Integer/10;
23         Finteger=Finteger*10;
24     }
25     Finteger=Finteger/10;
26     return Finteger;
27 }
28 bool IsPalindrome(__int64 iCandidate)
29 {
30     if(iCandidate<0)//负数肯定不是回文
31         return false;
32     else
33     {
34         if(iCandidate<=9)//长度为1的整型数肯定是回文
35             return true;
36         else
37         {
38             //获得逆转值
39             __int64 iSrc=iCandidate;
40             __int64 iDst=0;
41             __int64 iPivot=0;
42             __int64 iPower=0;
43             //获得iCandidate的逆转值
44             while(iSrc!=0)
45             {
46                 iDst=iDst*10+iSrc%10;
47                 iSrc=iSrc/10;
48             }
49             //比较正序值与逆转值;如果一致,则是回文;否则不是回文
50             if(iDst==iCandidate)
51                 return true;
52             else
53                 return false;
54         }
55     }
56 }
57 int main()
58 {
59     __int64 n,a[10000],flag;
60     while(scanf("%I64d",&n)!=EOF)
61     {
62         int mark=flag=0;
63         a[flag++]=n;
64         while(!IsPalindrome(n))
65         {
66             n=n+FINTE(n);
67             a[flag++]=n;
68             mark++;
69         }
70         printf("%I64d
",mark);
71         printf("%I64d",a[0]);
72         for(int i=1;i<flag;i++)
73             printf("--->%I64d",a[i]);
74         printf("
");
75     }
76     return 0;
77 }
原文地址:https://www.cnblogs.com/A-FM/p/5523190.html