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-08-22 20:39:44 GURUPREET SINGH
do we need to consider 0 as an input??

(reply by cyclops) Positive means greater than zero.

Last edit: 2014-08-22 23:00:56
2014-07-30 00:50:18 Hidenori
It's very easy to write bruteforce solution, so it was really easy to test!
2014-07-27 17:31:11 LeppyR64
Read the problem statement carefully there have been many posts on the forum with people missing the same detail:
"For a given positive integer K of not more than 1000000 digits"
2014-07-26 20:52:06 Nakul Mohan
nice problem...AC finally :)
2014-07-21 16:28:30 Zishan Ahmad
what is the upper limit of t ?
2014-07-13 06:38:05 Yevgen Yampolskiy
WARNING: last line does not have terminating '\n'. If you implement your own I/O library then you may run into an issue (as I did)

Last edit: 2014-07-13 17:43:42
2014-07-05 12:36:16 Wasim Thabraze
Huh! Finally AC after a 24hr struggle!

Last edit: 2014-07-06 05:59:45
2014-06-26 21:40:34 Mitch Schwartz
@ankush: There is no such feature. (This is mentioned at http://www.spoj.com/tutorials/USERS/#submit -- "Input and output data used by SPOJ judge to decide whether your solution is correct or not are set by problem-setter (person who adds problems) and are hidden. Many of problems has tricky test data so the ability to form you own and comprehensive test cases is very useful.")
2014-06-26 20:56:46 ankush
How can I have the test cases which were given to my program during submission and validation ?
2014-06-26 20:40:48 Mitch Schwartz
@Asheesh: Complaining angrily about not knowing how things work on the first day of joining a site isn't what I would call interesting. (1) Python is a slower language. There are several Python3 solvers for this problem, but you may need to pay more attention to optimisation concerns compared with other languages; (2) NZEC in Java should mean an exception was thrown -- an error that could be prevented by careful programming; (3) compilation errors are the easiest for users to diagnose; you can click on "compilation error" and read the error yourself. You can also see the name of the compiler when you submit. It should be no surprise that some compilers behave differently from others.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.