PalindromeProblem code: DPC206 |
All submissions for this problem are available.
Palindrome
A simple recursive method to generate a numeric palindrome from any number is to reverse its digits and add it to the original. If the sum is not a palindrome (which means, it is not the same number from left to right and right to left), repeat this procedure. For example for 195:
195 + 951 = 786
786 + 687 = 1473
1473 + 3741 = 5214
5214 + 4125 = 9339 Resulting palindrome
In this particular case the palindrome 9339 appeared after 4th addition. This method leads to palindromes in a few step for almost all of the integers. But there are interesting exceptions. 196 is the first number for which no palindrome has been found. It is not proven though, that there is no such a palindrome.
Your task is to write a program that gives the resulting palindrome and the number of iterations (additions) to compute it. All tests data in this problem will have an answer, will be computable with less than 1000 iterations (additions), which will yield a palindrome that is not greater than 4,294,967,295.
Input
The first line will have a number N (0<N<=100) with the number of test cases, the next N lines will each have a number P to compute its palindrome.
Output
For each of the N numbers you will have to write a line with the minimum number of iterations (additions) to get to the palindrome and the resulting palindrome separated by one space.
Sample Input
3
195
265
750
Sample Output
4 9339
5 45254
3 6666
| Author: | rushikesh30 |
| Date Added: | 10-03-2010 |
| Time Limit: | 5 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments

Fetching successful submissions

Please register at
Please register at http://bit.ly/DSPPC2_Register to claim prizes and certificates.
Admin: The aim of this
Admin: The aim of this contest is to promote programming and not to adjudge the best programmers. We request the participants to maintain a Healthy Competition. Any mal-practices if found will lead to Disqualification from the Series. If any such codes have been submitted consider submitting fresh codes.
The CodeChef Rankings are not
The CodeChef Rankings are not accepted Directly. Some Mal-Practices have been observed and Strict action would be taken.