Sphere Online Judge

SPOJ Problem Set (classical)

5. The Next Palindrome

Problem code: PALIN

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.


The first line contains integer t, the number of test cases. Integers K are given in the next t lines.


For each K, output the smallest palindrome larger than K.




Warning: large Input/Output data, be careful with certain languages

Added by:Adrian Kosowski
Time limit:2s-9s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Languages:All except: NODEJS PERL 6

hide comments
2014-10-22 21:01:11 Thiefds
What means "For a given positive integer K of not more than 1000000 digits"?
2014-10-16 11:46:23 wi34rd
Check: 999 1000 1001 1002 1010
2014-10-10 10:25:14 Vamsi Krishna Avula
in case you are getting wa, try 9, 99, 999 e.t.c
2014-10-10 09:40:53 legend80s
my code (in c++) runs fine in my computer, but got a Wrong Answer after my submission, can someone give me some test cases, or just give me some hint about how to test it.
2014-10-10 07:51:43 Suryakalyan Rani
Completely missed the part "K of not more than 1000000 digits"
2014-10-08 08:50:12 Govinda
in java StringBuffer has reverse() ,so reverse and compare them

Last edit: 2014-10-08 08:50:30
2014-10-06 00:48:18 Ramon
I need some help, please. My code runs fine in my machine but gets a WA. Can someone post a good set of test cases, please?
2014-10-04 20:12:33 Abhay Mittal
I am getting WA. Can anyone provide me with some sample test cases?
2014-10-04 08:14:38 karan
nice problem on string parsing :)
2014-10-04 00:09:30 Apurva Priyadarshi
@rubal gupta pes college wapas aao tab bata denge
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.