Submit | All submissions | Best solutions | Back to list |
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.
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 |
Date: | 2004-05-01 |
Time limit: | 2s-9s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS PERL6 |
hide comments
|
||||||||||||||
2019-08-05 12:49:50
I think there might be something wrong with this problem / its judge. Here's what i did: I made a checker program to test the output of the palindrome program, it verifies if it's a valid palindrome, if it's bigger than the input, and if there are no palindrome bigger than input and smaller than output. then i tested it with that (after modifying palin to output the input as well, so that checker knows what it's dealing with): ruby -e "puts (100000001); puts (0..100000000).to_a" | ./palin | ./checker 2> log_errors.txt which tests every number from 0 to 100,000,000. Found no issue. i then made a generator of random numbers strings of random length up to 1,000,000,000 digits, and ran ./gen | ./palin | ./checker after running for more than 3 hours, several times, i found no case where the output was wrong. So i thought maybe the checker was wrong, and tested the checker. It does tell me properly when the output is wrong, but to make sure i searched the internet for a source code for a palindrome program that does passes the judge. I submitted it myself to make sure it passed. I called this program "ref" Then i ran the tests again: ruby -e "puts (100000001); puts (0..100000000).to_a" | ./ref > ref_output ruby -e "puts (100000001); puts (0..100000000).to_a" | ./palin > my_output diff ref_output my_output No difference at all. I generated a test file of 10,000,000 random test cases with the generator, added some edge cases, then ran cat test_file | ./ref > ref_output cat test_file | ./palin > my_output diff ref_output my_output No difference. Is there something wrong in my tests ? Is there something i don't understand about the input ? Here are my files : <snip> Last edit: 2022-07-26 22:14:09 |
||||||||||||||
2019-08-01 16:35:34
Hi, inputing 09 in the toolkit tester (http://spojtoolkit.com/test/PALIN) gives 0 as the answer. I don't get it, shouldn't it be 11 ? |
||||||||||||||
2019-07-13 08:27:17
1->2 |
||||||||||||||
2019-07-08 16:57:29
Before writing code, try to think of as many tricky test cases to cover all cases. then this problem became easy |
||||||||||||||
2019-07-05 18:53:03
it take me 5h <snip> Last edit: 2022-07-26 22:14:42 |
||||||||||||||
2019-07-03 21:45:19
https://stackoverflow.com/questions/7934519/a-better-algorithm-to-find-the-next-palindrome-of-a-number-string/8187788#8187788 This might help. |
||||||||||||||
2019-07-03 12:18:16
I will say, just be careful of edge cases and its simple, HINT :- use char array, it might be helpful(initially i tried with int, and then switched to char array :P) Question difficulty :- easy Implementation difficulty : - HARD |
||||||||||||||
2019-06-30 12:26:52
time limit exceeded Last edit: 2019-06-30 12:27:22 |
||||||||||||||
2019-06-28 08:09:48
Help? not able to figure out the problem.I'm not even using loops then also its giving tle..I'm coding in python.. |
||||||||||||||
2019-06-27 19:36:31
My code is correct but it is showing TLE.Any help?I am using Java. |