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

hide comments
2014-11-19 04:10:12 Rafael Cunha de Almeida
I can't figure out which number is breaking my code :( I've made a test case of thousands of random numbers and they all passed. I'm out of ideas :(
2014-11-18 12:23:02 NPR
Hi! I want to know if anybody can send to me a list with all cases of input ? My problem is that I'm not sure if input can be for example: 005 and if it can, which is the next palindrome ? 6 or 101 ? Thank you
2014-11-10 21:44:08 HARSH MADHOGARIA
http://ideone.com/cOQfuo
cnt find the mistake please help!!!
2014-11-07 10:03:50 Kishan Patel
Ans for 000000 should have been 1 or 11 but its different..showing with toolkit!! anybody to explain??
2014-11-06 09:36:22 Manraj Singh
This is one question that teaches you case handling.

SPOJ please start saving default complier.Costed me one Compilation error. :'(

[reply by cyclops: Did you go to http://www.spoj.com/myaccount/edit/ and select a default programming language?]

Last edit: 2014-11-06 12:05:31
2014-11-03 16:48:14 Dario Pavlovic
AC. Number 50 :)

Last edit: 2014-11-03 16:57:42
2014-11-03 00:18:32 Samuel
NZEC with Java when closing the streams
NZEC with Java when not closing the streams
NZEC wit Java when "return;"
Can someone explain how to get Accepted.

[reply by cyclops: Your comment suggests that you hardly put any thought into the debugging process at all. You tweaked a few random things and then acted as though you've done as much debugging as could be reasonably expected and now it's up to other people to step in and help you out.

Narrow down what is causing NZEC strategically. You can comment out sections of code, add try blocks, add throws clauses, etc. Essentially, the idea is to start from a program that does nothing (but compiles and runs without throwing an exception), and then incrementally add pieces of code until an exception is thrown. Then figure out why that exception is being thrown and look for ways to avoid it. Read the documentation if needed.

Some useful resources include ideone.com and the forum. Be sure to read the forum guidelines as described by TripleM and Leppy if you wish to post there.]

Last edit: 2014-11-03 01:33:06
2014-10-26 10:01:04 Sergey Skupoy
NZEC in Haskell. Something is wrong with EOL.

Last edit: 2014-10-31 23:19:29
2014-10-25 10:54:26 karan
finally :') :') this gave a strong feel :D :')
2014-10-23 06:55:11 huangqi-hy
2 is one digit and 20 is two and 1,000 is four,so 1000000 digits means the number has 1000000 number in it
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.