Time limit exceeded in Next Palindrome

There is time limit exceeded in my program while on Ideone it is taking only some moments.
Can anyone please tell me why?
How to now make changement in my program, some ideas?

give a link to your code on ideone.com , or post your code here… we cannot advice you accurately if we cannot see your code :slight_smile:

Is there any compiler which can show the exact time taken?

First of all even if you are able to optimize your code you’ll get WA since for

Input:
1
1

Output is:

2

Secondly read the constraints :

For a given positive integer K of not more than 1000000 digits

And when i tested your code on


1
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

Your code fails to produce output

You may check these links:

Above test case on AC code: http://ideone.com/eS6yRV

Above test case on your code: http://ideone.com/U2ez6z

Your code might not able to compute large numbers…!

Just debug your code or implement a new algorithm… :slight_smile:

EDIT:

To answer your question about time taken for execution

You may modify your code by adding this macro

#ifndef ONLINE_JUDGE
freopen("a.txt", "r" , stdin);
freopen("a.out", "w", stdout);
#endif

and passing input through a file named a.in which should be stored in same directory in which source code is saved and just by running your code output will be saved to a.out and you’ll get the execution time on command line.

After adding that macro your code should look this way: http://ideone.com/1TPX04

Alternate Method [ More Preferable ]:

You may add this code to your source code

#include <time.h>
int main(void) {
    clock_t tStart = clock();
    /* Do your stuff here */
    printf("Time taken: %.5fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}

Resource for above code: http://stackoverflow.com/questions/876901/calculating-execution-time-in-c