Submit  All submissions  Best solutions  Back to list 
NEXTPREV  The next and the previous palindrome 
Wersja polska  English version 
Input
The input consist of unknown number (lower than 100) of tests. Each test is a line with two integers x and y (0<=x<=2*10^{9}, length of y is at most 1000).
Output
For each test You should print:
 the next palindrome of y  if x is even
 the previous palindrome of y  if x is odd
Example
Input: 10 9029
11 9029 Output:
9119
9009
Note: Leading zeroes don't occur in the input and shouldn't occur in the output.
Added by:  Piotr Kąkol 
Date:  20110613 
Time limit:  1.620s3.286s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: SCM qobi 
hide comments


20120319 09:00:01 Piotr KÄ…kol
@De bugging  Your reading is invalid. Do not use cin.eof() unless You really need it. 

20120318 08:41:35 debugging
Could You write me what's wrong with #6677687 output? 

20110701 12:49:06 Piotr KÄ…kol
@Jander  No negavite numbers at all. 

20110630 10:28:50 Jander
Just for further clarification of hallvabo's question, can y be negative ? Ie we have to handle palindromes of 1234 for example. 

20110628 22:14:53 Piotr KÄ…kol
@hallvabo  Yes, for y=0 You print 2 instead of 1. But y>0 for previous palindrome. 

20110628 20:43:57 Hallvard Norheim Bø
Can y be less than 1? For what input does #5309983 fail? 

20110616 17:18:14 Piotr KÄ…kol
@hallvabo  9 I added a note. Thanks for Your remark. 

20110616 12:04:12 HWK
@Piotr: Thanks but seems there are more special cases. I'll look for them. Last edit: 20110617 13:33:55 

20110615 21:16:05 Hallvard Norheim Bø
What about leading zeroes? 11 11 => 010 or 9? 

20110615 20:17:28 Piotr KÄ…kol
Of course. :) 101 10 > 9 not 00 