Search Result Conjecture
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 1524 accepted submission (s): 945
Problem description is a positive integer. If the read from left to right (called positive order number) is the same as the read from right to left (called reverse order number), such a number is called the return number. Take a positive integer. If it is not a return number, add the number to its reverse order number. If it is not a return number, repeat the above steps until the number is obtained. For example, 68 is changed to 154 (68 + 86), then to 605 (154 + 451), and finally to 1111 (605 + 506), while 1111 is the number of replies. Therefore, a mathematician proposed a conjecture: No matter what positive integer is at the beginning, after a finite ordinal number and a descending order number are added, a return number is obtained. So far, I do not know whether this conjecture is true or false. Compile Program Verify.
Each input row has a positive integer.
Note: ensure that the intermediate result of the input data is less than 2 ^ 31.
Output corresponds to each input. Two rows are output, one is the number of transformations, and the other is the transformation process.
Sample input27228
37649
Sample output3
27228 ---> 109500 -----> 115401 ---> 219912
2
37649 ---> 132322 ---> 355553
Authorsmallbeer (CRF)
Source hangdian ACM training team training competition (VII)
Recommendlcy
# Include < Stdio. h >
Int Change ( Int N)
{
Int A [ 20 ];
Int K = 0 ;
While (N ! = 0 )
{
K ++ ;
A [k] = N % 10 ;
N /= 10 ;
}
Int Res = 0 ;
For ( Int I = 1 ; I <= K; I ++ )
{
Res * = 10 ;
Res + = A [I];
}
Return Res;
}
Int Main ()
{
Int N, I, CNT;
Int Result [ 100 ];
While (Scanf ( " % D " , & N) ! = EOF)
{
CNT = 0 ;
Result [ 0 ] = N;
While (N ! = Change (n ))
{
N = N + Change (N );
Result [ ++ CNT] = N;
}
Printf ( " % D \ n " , CNT );
For (I = 0 ; I < CNT; I ++ )
Printf ( " % D ---> " , Result [I]);
Printf ( " % D \ n " , Result [CNT]);
}
Return 0 ;
}