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
|
||||||||||||||
2020-11-15 09:28:17
If you're getting wrong ans use these tc's: TC : 40 808 2133 9999999 999999 899998 3423355356 100001 46887767 9 99 0 1991 1239400 123999500 56442 56471 123456 1234567 77777777777 2991 3994 9999 5448 653434 101 199 0012100 0003 123456 1234567 9999 99999 1 2991 3994 9999 5448 65343454 100 4111 Ans : 818 2222 10000001 1000001 900009 3423443243 101101 46888864 11 101 1 2002 1240421 124000421 56465 56565 124421 1235321 77777877777 2992 4004 10001 5555 654456 111 202 0013100 0110 124421 1235321 10001 100001 2 2992 4004 10001 5555 65344356 101 4114 Sorry some values might be repeated. I got AC after 3 hrs of trying.. |
||||||||||||||
2020-11-06 19:44:38
i have been writing code in C and it works perfectly on Ideone and is giving correct output, but here I am getting error. It is showing wrong answer. Please help me... |
||||||||||||||
2020-10-25 06:53:04
Hey, does anyone know where can I get the input tests cuz I've tried the most optimal code I could but still exceed time limit, so I just want to k now where can I get the test to know how to optimize it |
||||||||||||||
2020-10-18 13:00:47
In C#, I tried with BigInteger and without it, the result is TLE. Can it be a limitation for C#? Please fine my solution below http://discuss.spoj.com/t/palin-the-next-palindrome-time-limit-exceeded/40347 |
||||||||||||||
2020-10-08 09:16:28
All the peeps who say that there solution is correct but they are getting WA, trust me, your solution is wrong. Now to identify the test cases where your solution goes wrong, try to write a code that solves the problem for numbers <= 10000 (this will be enough, I guess. solution can be easily found by incrementing this number till you get a palindrome), now use STRESS TEST with this solution and your original code, you will get the Test Cases that you need to take care of. (For Stress Test you can visit Errichto's YouTube channel). Hope This Helps! |
||||||||||||||
2020-09-09 19:26:45
be careful with "K is not more than 10^6 digits", so you can't use long long type to store the number. Also, TLE may because it try too many times. Last edit: 2020-09-09 19:28:13 |
||||||||||||||
2020-08-25 21:13:02
I'm getting SIGABRT,even though it is working successfully on ideone. |
||||||||||||||
2020-08-20 10:19:07
If you get "wrong answer", try to make you own comprehensive test suite: iterate from 0 to some large n, if n is a palindrome, your function must return it as a result for all the numbers from previous palindrome to n. |
||||||||||||||
2020-08-16 17:45:08 Shahin Ram Krishna
any guidelines on how to use cin and cout for SPOJ? my testcases are producing correct result. all the corner cases are checked but spoj throws wrong answer. can someone tell do I need to flush the stdin/stdout ? Last edit: 2020-08-16 17:46:00 |
||||||||||||||
2020-07-28 22:20:28
My code is all correct and working in ide but here it is exceeding time limit |