Help regarding the following code?

“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.”


int main()
    int reverse=0,i,flag=0,k,t,m;
   while( i != 0 )
      reverse = reverse * 10;
      reverse = reverse + i%10;
      i = i/10;
   if (m == reverse )
         flag=1;  }
     return 0;

@rohan1994 optimize ur algorithm…try to approach problem differently… otherwise it will take time… for eg if k=1002 ans should be 1111 so for every number reversing and checking will take time… plus i guess you use Turbo C ? please get on Gcc(gnu c compiler) compiler it is quite more robust and modern than turbo c. codechef now uses gcc 4.8.1, gcc4.7.2, gcc 4.3.2 so you should use ny one of them

Optimize your algorithm. If the approach you are using is taking too much time try a different way to solve this… I found this when i tried to solve this problem.

It also tried this while practicing in the begining. Its a tough one for me that time, so i left it but 1 week before i found the same one on spoj then i solved them both…


i use dev c++ with gcc 4.3.2 compiler