WA plz help :P

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!

O.o My code outputs 1001 when 999 is entered … it outputs 6006 when 5999 is entered … outputs 7 when 8 is enetered …

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!
http://ideone.com/XpXtqh

1 Like

Hey, btw did i tell you the same mistake last time as well? :stuck_out_tongue: Have you asked this question before and have i answered the same? :stuck_out_tongue: I remember, sort of

Hey, btw did i tell you the same thing last time as well? :stuck_out_tongue: Have you answered my question before and have i replied the same? :stuck_out_tongue: 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 -___-

Oh does it? http://ideone.com/MQXjKN
I dont see ur outputs -_-

1 Like

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

1 Like

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 :frowning:

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 :smiley: … go ahead

And atleast better than a WA, tle :stuck_out_tongue: WA frustrates u, tle doesn’t . So chill! :stuck_out_tongue:

1 Like

Sorry maybe i was kidding -- I need rest! --

1 Like

lol…

Though it is kind of an infinite loop. See thts where the problem lies. I added loop count to both codes this time
:-
http://ideone.com/16baLn
http://ideone.com/XpXtqh