Acm hdu 1282 echo number conjecture (simple question)

Source: Internet
Author: User
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 ;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.