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-04-10 17:00:48 Tej Pal Sharma
how much large the data is ?

Also how to figure what numbers to skip already or i have to iterate through every number

Got it after reading the comment below ! used strings

Last edit: 2014-04-10 19:55:50
2014-03-25 21:28:37 Aryan Raj
@any1 :
my code is showing wrong answer and i am a newbie. Please help
2014-03-22 07:25:24 Vikram Bhat
@bishma You should you readline in java or gets in c++ and similar line readers in other languages
2014-03-22 07:23:52 Vikram Bhat
@Akshay print the next digit as single digit is also a palindrome
2014-03-22 04:31:05 Bishma Radheya Stornelli Ortega
My code takes like a minute just reading a string of 1,000,000 :S. Should I read and process the output char by char or what?
2014-03-21 20:57:46 Akshay Madan
@adrian what do we do in case of single digit nos.??

Last edit: 2014-03-21 21:00:29
2014-03-20 17:21:28 lakshay bansal
got answer in my system but here shows wrong answer
2014-03-17 20:08:41 Zeus
@adrian please explain where is my code consuming more time ???? ID: 11268758
2014-03-05 05:36:28 Vineet

Last edit: 2014-03-05 16:38:13
2014-03-04 21:54:42 rishitha
please check and tell why is 1184823 wrong
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.