PALIN - The Next Palindrome
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
I really should grow the habit of reading the question before answering. I solved the question using integer types thinking the number would be less than 1000000, but it was the number of digits :(
All test cases running on eclipse and ideone (java).. In spoj, NZEC runtime error. HELP PLSSS !!!! Its super frustrating..
Don't use Big Integer its too slow , I suggest you use int array to store digits. when K =191 makes sure its output is 202 not 101. GOOD LUCK!
My code is working correctly in my IDE but run time error here...!! pls help and all my test cases are working....!!Last edit: 2016-07-18 04:50:53
Last edit: 2016-07-16 20:58:34
Thanks to @Dushyant Singh , 2 times WA using scanf. AC after switching to cin
I'd just like to say to all of you who are getting WA and have tried all of those cases that people posted, got them right, and got right answer in ideone, or wherever you tested your code. When you print answers print them in one line separated by a space. So no endl,\n or anything like that only ' '. Trust me I got 10+ wrong answers because of this.
Please make it clear that the value of 'k' should be less than 1000000 or the value of 'k' should contain less than 1000000 'digits'? As in the question it is mentioned as 'not more than 1000000 digits'.
what about leading zero ? do we need to take care of them?