朱色虫居
Pages
Home
Featured Posts
2006/10/03
10018-Reverse and Add
/*
"Reverse and Add"
Level:2.5
Date:2006/10/2
技巧:一個數字如:591 可以看成 ((5*10)+9)*10+1
要轉成195 即 ((1*10)+9)*10+5
*/
#include
unsigned long reverse(unsigned long);
main(){
long int input=0;
long int rev=0;
int n=0,iter=0;
scanf("%d",&n);
while(n-- > 0){
scanf("%lu",&input);
while(rev !=input){
input+=rev;
rev = reverse(input);
iter++;
}
printf("%d %lu\n",--iter,rev);
rev=iter=0;
}
}
unsigned long int reverse(unsigned long a){
unsigned long r=0;
while(a!=0){
r=r*10;
r += a%10;
a /= 10;
}
return r;
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment