please help…i’m getting wrong answer. i don’t know wats wrong with the code . Here is the link to my solution
Click Here
Very simple mistake. Most of the people make the same in this problem. Say if the string is already a palindrome, then you should print the next one. It is written clearly that you print a palindrome larger than the number. LARGER not equal. So if your input is say 9999 you have to print 10001. Check out what your code does on this input.
Solution :- First add 1 to whatever number u get. This way if the string is a palindrome. It no more remains a palindrome unless the input is 1 to 8. Then check if the string (after adding 1) is a palindrome or not, bcz say if the input is 8887. U add 1 it becomes 8888 ( a palindrome) . If it is a palindrome simply print it. If not go for your method (which u have already), rest everything is correct!
Hey, btw did i tell you the same mistake last time as well? Have you asked this question before and have i answered the same? I remember, sort of
O.o My code outputs 1001 when 999 is entered … it outputs 6006 when 5999 is entered … outputs 7 when 8 is enetered …
Hey, btw did i tell you the same thing last time as well? Have you answered my question before and have i replied the same? I remember, sort of
Ahh, instead of copying my answer, y dont u give the test case i gave to you. Y dont u try 9999 and see for urslf? And then say if your code is right or wrong? Will you once?
and look carefully 9999 and not 999.
outputs 10001 for 9999 , 100001 for 99999 , 1000001 999999 and so on -___-
Try it with c++11 and u’ll get it right! Right now u r doing with 4.3.2 ! And i really dont know the reason for this -_____________- Just know it does give u a wrong answer on 4.3.2
wtf …i copied the same code onto my codeblocks IDE and works perfectly fine o.O …
I know! Just submit it with C++11 . Try and then tell me. I tried it with C++11 in ideone to get a right answer. 4.3.2 gives wrong answer. Trying to see what u have u used here thts causing this
TLE on C++11
Can i ask this question on discuss? Can i submit ur code? I have ideone samples of both c++11 and c++4.3.2 i also want to know the reason. So shall i? Someone good with compilers can tell
sure … go ahead
And atleast better than a WA, tle WA frustrates u, tle doesn’t . So chill!
And btw hellboy 054, u get WA in C++11 because your loop never ends.! I did some modification to check your code. Just a test! And see the result!
Sorry maybe i was kidding -- I need rest! --
lol…
Though it is kind of an infinite loop. See thts where the problem lies. I added loop count to both codes this time
:-