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.

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 Kosowski
Date:2004-05-01
Time limit:2s-9s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Languages:All except: NODEJS PERL 6 SCM chicken

hide comments
2015-01-29 21:08:14 Amit Kumar Kannaujiya
Hi friends
i am getting NZEC in my solution can any one help me to find root cause ?
http://www.spoj.com/submit/PALIN/id=13553499
language java.
Thanks in advance !
2015-01-23 19:46:08 Micha³ Kryszak
@Sreeraj You're right. Every 1-digit number is palindromic, hence after 5 comes 6, after 6 comes 7 etc.
2015-01-23 08:42:06 Sreeraj
2015-01-14 14:05:49 Anirudha Bose
Keep the following test cases in mind:
9999 -> 10001
99999 -> 100001
5 - > 11
10 -> 11
1299976 -> 1300031

why is the next palindrome for 5 11 ?
should'nt it be 6 ?
it satisfies the definition of palindrome given in the question
2015-01-16 19:55:27 Adalberto Florentino Cleto
my program is perfect with string and all the cases done but de judge tell me WA, some body put more examples
2015-01-14 20:43:19 the_imp
http://ideone.com/7ejK6Y
getting sigbart...plz help
2015-01-14 14:05:49 Anirudha Bose
Keep the following test cases in mind:
9999 -> 10001
99999 -> 100001
5 - > 11
10 -> 11
1299976 -> 1300031

Last edit: 2015-01-14 14:07:06
2015-01-13 17:38:40 Kaushik Nath
i am taking input through strings
and getting correct answer at ideone but not at spoj
please help
2015-01-12 19:48:47 Rajat
extremely good question. :)
2015-01-08 15:28:22 utkarsh mishra
it is all about nines....
2015-01-08 10:13:59 praveen anuranjan
http://ideone.com/mA5RqI every answer is coming true and still giving WA someone plzzz help

Last edit: 2015-01-09 10:58:53
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.