回文数猜想
2016-05-24 13:56
330 查看
....理工上用了 long long 才过 .....
#include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<queue> #include<vector> #include<set> #include<stack> #include<string> #include<sstream> #include<map> #include<cctype> #include<limits.h> using namespace std; __int64 FINTE(__int64 Integer) { __int64 Finteger=0; while(Integer!=0) { Finteger+=Integer%10; Integer=Integer/10; Finteger=Finteger*10; } Finteger=Finteger/10; return Finteger; } bool IsPalindrome(__int64 iCandidate) { if(iCandidate<0)//负数肯定不是回文 return false; else { if(iCandidate<=9)//长度为1的整型数肯定是回文 return true; else { //获得逆转值 __int64 iSrc=iCandidate; __int64 iDst=0; __int64 iPivot=0; __int64 iPower=0; //获得iCandidate的逆转值 while(iSrc!=0) { iDst=iDst*10+iSrc%10; iSrc=iSrc/10; } //比较正序值与逆转值;如果一致,则是回文;否则不是回文 if(iDst==iCandidate) return true; else return false; } } } int main() { __int64 n,a[10000],flag; while(scanf("%I64d",&n)!=EOF) { int mark=flag=0; a[flag++]=n; while(!IsPalindrome(n)) { n=n+FINTE(n); a[flag++]=n; mark++; } printf("%I64d\n",mark); printf("%I64d",a[0]); for(int i=1;i<flag;i++) printf("--->%I64d",a[i]); printf("\n"); } return 0; }
相关文章推荐
- C语言字符串数组与字符串指针详解
- 第10 11周 项目三 警察与厨师 (1)
- JS this
- 第11周-课后实践(4)
- linux基础命令学习(六)文件的特殊属性
- BZOJ1036 [ZJOI2008] 树的统计Count
- Mysql Join语法解析与性能分析
- Android Studio 代码混淆Gradle编译报input jar file is specified twice
- hdu 1385 Minimum Transport Cost(最短路+输出路径)
- 数据结构 --- 栈和队列
- SQL Server 维护计划实现数据库备份
- android之MTP框架和流程分析
- s3cmd 操作手册
- hive sql 语句学习
- 前端福利!10个短小却超实用的JavaScript 代码段
- textView结合selector点击改变文字颜色
- ? extends T 与 ? super T
- 【例题】【动规】NKOJ 1796 数字金字塔
- Android 反编译、Smali插桩、二次打包
- Python object new style class inheritance