题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1282
27228 37649
3 27228--->109500--->115401--->219912 2 37649--->132322--->355553
代码如下:
#include <cstdio> int Pa(int a) { int sum = 0; while(a) { sum+=a%10; a = a/10; if(a) sum*=10; } return sum; } int main() { int num; int r[10000]; while(~scanf("%d",&num)) { int k = 0; r[k] = num; while(num!=Pa(num)) { k++; r[k] = num+Pa(num); num = r[k]; } printf("%d\n",k); for(int i = 0; i < k; i++) { printf("%d",r[i]); printf("--->"); } printf("%d\n",r[k]); } return 0; }
原文地址:http://blog.csdn.net/u012860063/article/details/39084309