HDU 1282 回文数猜想

http://acm.hdu.edu.cn/showproblem.php?pid=1282

两种想法,用字符串处理或是用数字处理,这里数字处理更简单

View Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int IsHw(int n)
{
int p,ans=0;
p=n;
while(n)
{
ans=ans*10+n%10;
n/=10;
}
if(ans==p)return 1;
return 0;
}
int Nx(int n)
{
int ans=0;
while(n)
{
ans=ans*10+n%10;
n/=10;
}
return ans;
}
int main()
{
int n,cnt,p,i;
int a[1100];
while(~scanf("%d",&n))
{
cnt=1;
p=n;
while(!IsHw(n))
{
n+=Nx(n);
a[cnt++]=n;
}
if(cnt-1!=0)
printf("%d\n",cnt-1);
else
printf("1\n");
printf("%d",p);
for(i=1;i<cnt;i++)
printf("--->%d",a[i]);
putchar('\n');
}
return 0;
}
原文地址:https://www.cnblogs.com/xiaohongmao/p/2433606.html