您的位置:首页 > 其它

回文数猜想

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: