A strange behaviour of sprintf() in c++ library

bug
c-plus-plus
pointer
sprintf
sscanf
string
tle

#1

I just found strange thing about sprintf() (c++ library function).

have a look at these two solutions

[Time limit Exceeded solution][1]

[Accepted Solution][2]

the only difference between them is that, I used

sprintf(a,"%d%c",n,'\0');

in TLE solution,

in AC solution I replaced above sprintf() with

sprintf(a,"%d",n);

You can also observe that ACed solution took only 0.01s and 2.8MB memory

but TLE solution took around 11.8MB
[check here][3]

And one more thing program that gave TLE runs in 0s in [IDEONE][4] with extreme input data
so is it a bug in [CODECHEF][5] itself

Somebody please explain me is this a bug or some considerable unknown operation is happening here.

Thanks in advance.
[5]: http://www.codechef.com
[4]: http://ideone.com/e.js/jMhUVJ
[3]: http://www.codechef.com/status/FCTRL2?sort_by=All&sorting_order=asc&language=All&status=All&handle=hkbharath&Submit=GO
[2]: http://www.codechef.com/viewsolution/3938145
[1]: http://www.codechef.com/viewsolution/3938157


#2

It is rather strange. Codechef and Ideone run on the same SPOJ server so i do not understand why this problem is happening.


#3

Actually I got TLE for the same solution(which got TLE in CODECHEF) in SPOJ also…


#4

I think it has something to do with the version of C++ used. I think different versions must have caused the problem