一直反轉數字然後加起來,就可以得解。
P.S.
- 數字的反轉可以看reverse()這部份是怎麼寫的。
- 本題至少要加1次。
C++(0.008)
/*******************************************************/
/* UVa 10018 Reverse and Add */
/* Author: LanyiKnight [at] knightzone.studio */
/* Version: 2011/11/29 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;
unsigned int reverse( unsigned int num ){
int rev = 0;
while( num ){
rev = rev*10 + num%10;
num /= 10;
}
return rev;
}
int main(){
int N, times;
unsigned int num, rev;
while( scanf( "%d", &N ) != EOF ){
for( int i = 1 ; i <= N ; i++ ){
scanf( "%u", &num );
times = 0;
rev = reverse(num);
do{
num = num + rev;
times++;
rev = reverse(num);
}while( num != rev );
printf( "%d %u\n", times, num );
}
}
return 0;
}