#include<stdio.h> unsigned long reverse(register unsigned long); int main() { register unsigned long n,num,rev,i; //freopen("in.txt","r",stdin); scanf("%lu",&n); while(n--) { scanf("%lu",&num); for(i=0;;i++) { rev=reverse(num); if(!(num^rev)) break; num=num+rev; } printf("%lu %lu\n",i,num); } return 0; } unsigned long reverse(register unsigned long num) { unsigned long r=0; while(num) { r=r*10+num%10; num=num/10; } return r; }
Wednesday, 1 June 2011
uva 10018-Reverse and Add
Subscribe to:
Post Comments (Atom)
is there a place where we can see the problem to go along with the solution
ReplyDelete