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
hide comments
Abhishek Prasad:
2015-07-11 01:58:55
14643636.. can anyone please suggest me what did I do wrong here? |
|
poojan :
2015-07-10 07:18:39
giving me wrong ans :
|
|
jatin240396:
2015-07-08 18:26:15
check for the cases 421999767,429964 |
|
dawidmt:
2015-07-08 02:38:16
I made brute force algorithm, compared it with my algorithm using 10000 random numbers 0..10000, got exactly the same results, but still WA for non brute force. Could someone give me some tricky examples for testing (I already tested most from comments)?
|
|
thearkguy:
2015-07-07 20:08:13
<snip> Can anyone tell me why am I getting a WA? Got it, thanks anyways. Last edit: 2022-07-26 22:22:47 |
|
Loong:
2015-07-06 19:57:42
<snip>
|
|
Punit Bhatt:
2015-07-02 07:53:08
<snip>
|
|
deeksha:
2015-07-01 18:31:46
my code is showing coorect output still it is showing wrong answer |
|
Jesus E. Larios Murillo:
2015-07-01 05:51:25
Okay for those people coding in c. I have been taught that the correct way of getting input is to use fgets(buffer, buffer_size, stdin). This avoids overflows. This brings in the new line character also, so I follow it by buffer[strlen(buffer) - 1) = '\0', to get rid of it. This is what I tried to do with this problem, and I have spent HOURS trying to figure out why it doesn't work, even though everything seems right. Finally, serendipitously, I changed the fgets to scanf("%s", buffer), and the code that was not passing before is now passing. I have no words to describe this feeling. Can someone tell me why fgets doesn't work?
|
|
Tanuj Kumar:
2015-06-27 08:42:24
This shows WA all the time. Hours of effort for nothing.
|
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 |