HDU 1282 回文数猜想

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

水题。

跟在创新工场遇到的一个问题类似,整数串判断回文。

由于题目所称整数的限制,数组的大小不是太好取。参考网上的经验值。

#include <stdio.h>
#define MAX_ARRAY 100
int ReserveNum(int a)
{
int ret = 0;
while(a)
{
ret = ret *10 + a%10;
a /=10;
}
return ret;
}

int main()
{
int first,last;
int array[MAX_ARRAY];
while(scanf("%d",&first)!= EOF)
{
int count = 0;
while(first != (last =ReserveNum(first)))
{
array[count++] = first;
first +=last;
}
int i;
printf("%d\n",count);
for(i = 0; i < count; ++i)
printf("%d--->",array[i]);
printf("%d\n",first);
}
return 0;
}



原文地址:https://www.cnblogs.com/westfly/p/2403390.html