Whenever i type a code i execute it and only f it works i submit. But every time i submit it shows as wrong answer but a similar answer with same logic but with different variable names and function names are accepted. Can someone explain why it is so?
int n, reversedInteger = 0, rem, originalInteger,times;
originalInteger = n;
// reversed integer is stored in variable
while( n!=0 )
rem = n%10;
reversedInteger = reversedInteger*10 + rem;
n /= 10;
// palindrome if orignalInteger and reversedInteger are equal
if (originalInteger == reversedInteger)
This is my code for The block game problem. Why is it wrong? I saw a similar answer which was accepted!
There is a silly mistake in your code, you have to make reversedInteger=0 in all the test cases meaning at the beginning of while loop. I edited that and got accepted, I bet you did such a mistake all the times because it doesn’t matter what you name a variable Edited code - https://www.codechef.com/viewsolution/18821770
Hey! i dont understand how its a mistake first of all. I executed it outside codechef i got the expected output. Even by declaring reversedinteger=0 in the beginning is applicable for all test cases right?
You see consider multiple test cases like
After the first test case reversed integer is 321 it remains 321 and you execute for second test case so it would become 321765 you can check this by printing reverse integer at the end of each test case so it would not give the expected answer as the reversed integer made by your code is wrong