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:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: NODEJS PERL 6

hide comments
2014-09-30 14:52:26 Vamsi Krishna Avula
I think the code is fine, but I am getting WA, any common errors?
2014-09-27 22:47:10 RUBAL GUPTA
@calor: i saw that yu have done this code plz help me out for this code alse plz give me the gmail id

2014-09-26 16:37:55 Mansi Gupta
what is meant do not display leading zeroes can you give an example what is leading zeroes?
2014-09-25 12:08:28 shikhil gupta
2014-09-24 21:38:18 sachin
give some inputs and their outputs
to check program
2014-09-23 22:42:39 Pawan Bathe
Can anybody help understand, why is this wrong <script src="http://ideone.com/e.js/jjIvBQ" type="text/javascript" ></script>?
2014-09-23 11:41:49 Huibert-Jan Nieuwkamer
Although it has been said before: For all of you lot using python and sys.stdin.readline(), use input() (or raw_input() depending on python #) instead to read input. The last line has no line ending character.
2014-09-21 20:54:45 RUBAL GUPTA
plzz help
2014-09-21 20:54:30 RUBAL GUPTA
my code is working in codeblock bt showing wrong anwer at sumbit
2014-09-18 04:42:57 lyn
AC finally as a SPOJ newbie.. the source code can be fairly simple if the correct strategy is chosen .. and as the guys have already pointed out, the 'integer K of not more than 1000000 digits' indicates using atoi only yields WA
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.