Submit | All submissions | Best solutions | Back to list |
PALIN - The Next Palindrome |
A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. Numbers are always displayed without leading zeros.
Input
The first line contains integer t, the number of test cases. Integers K are given in the next t lines.
Output
For each K, output the smallest palindrome larger than K.
Example
Input: 2 808 2133 Output: 818 2222
Warning: large Input/Output data, be careful with certain languages
Added by: | adrian |
Date: | 2004-05-01 |
Time limit: | 2s-9s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS PERL6 |
hide comments
|
||||||||||||||
2016-05-24 16:18:50
Finally accepted after 2 WA! check for tricky cases: input: 7 24 9 0000000 999999 2456 2998 29999 output: 33 11 0001000 1000001 2552 3003 30003 PS:You won't get any points for solving this :P Last edit: 2016-05-24 16:19:10 |
||||||||||||||
2016-05-24 14:57:36 Kirill Diduk
In this problem, it is expected that a single-digit number is NOT a palindrome. So, when you get a single-digit number as an input, the output should be 11. |
||||||||||||||
2016-05-21 14:47:44
Wth! Working everytime in my compiler but says wrong output here.... What's going on? Edit: Ok.... I read 1000000 not 1000000 'digits'.... Oopsss Last edit: 2016-05-21 14:50:04 |
||||||||||||||
2016-05-18 08:51:54
Be careful while comparing. Put ' ' between numbers. Cost me 7 WA's :p |
||||||||||||||
2016-05-12 14:37:59 Gaurav Kumar
hey , Is 1000 a palindrome ? 0001000 maybe |
||||||||||||||
2016-05-11 22:25:19
If you use recursion you will get NZEC (in python at least) |
||||||||||||||
2016-05-10 20:22:01
Can anyone tell me how to rectify NZEC runtime error? |
||||||||||||||
2016-05-09 14:00:37
I'm unable to get the output to thi question. can anyone help me out with this. I'll send my code. |
||||||||||||||
2016-05-04 14:40:58
This is a great problem! I'm a beginner (this is my 10th day learning programing from nothing). It took me many tries but finally got accepted(c#). Tips for beginners like myself (POSSIBLE SPOILER ALERT): 1. No language can hold a 1000K digit number as a integer - you cannot work with ints and need to come up with some other mean to work with these numbers 2. For this reason, brute force (which i myself submitted like 5 times - stupid!) will never work 3. Remember the palindrome you come up with needs to be LARGER than the input number 4. Once you have it, check for all the tricky numbers: one digit numbers, 99, 12322, 898 and other that ppl have pasted in here 5. Be sure to optimize your program as much as possible 6. Keep trying :-) |
||||||||||||||
2016-04-27 14:06:43
time limit exceeded :( But it takes only 0.2 secs in ideone |