Sphere Online Judge

Computer geeks! Show off your skills and claim the job of your dreams! RecruitCoders.com

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:9s
Source limit:50000B
Languages:All except: PERL 6

hide comments
2012-05-26 09:30:55 ABHISHEK KUMAR
i am getting " WA "
can anyone give me more test cases please
here's my code:
http://ideone.com/jRmYc#
2012-05-23 22:03:39 chirag_coder
I am getting :
runtime error (SIGSEGV)
what does that mean ....plz reply
2012-05-23 15:03:19 Mani
why it is showing wrong answer??
can anyone help me please???
give me the sample inputs for which it is showing wrong answer????
its here ''http://ideone.com/vCOq4#ul_inouterr''

Last edit: 2012-05-23 15:06:22
2012-05-23 04:05:30 Kevin Dear
@mani: u r using long long int as the storage type whereas the problem says that the number of digits is 10^6
@chirag: Maybe you are using an array of size exactly 10^6 or less make it 10^6+1 at least

Last edit: 2012-05-25 06:19:09
2012-05-20 11:21:36 sandeep
Just a tip:The next palindrome of 1 is 2
2012-05-19 16:56:08 icensit
can somebody tell me the case where my logic is failing , my program id is 7013251

Last edit: 2012-05-20 07:33:16
2012-05-18 13:17:22 Toya
http://ideone.com/F7eKD

over here its giving me the proper output but why is it showing "Wrong Output"

Last edit: 2012-05-18 13:31:01
2012-05-17 11:14:37 Casper Castle
@sara , change your class name from plain to main. and submit . it will work..
2012-05-17 11:13:08 Casper Castle
please make clear 1 mil digits? integer?
2012-05-13 19:39:01 Kevin Dear


Last edit: 2012-05-23 04:05:27
SPOJ System © 2012 Sphere Research Labs | Projekty informatyczne i aplikacje na zamówienie. All Rights Reserved.