×

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

 0 I just found strange thing about sprintf() (c++ library function). have a look at these two solutions Time limit Exceeded solution Accepted Solution 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 And one more thing program that gave TLE runs in 0s in IDEONE with extreme input data so is it a bug in CODECHEF itself Somebody please explain me is this a bug or some considerable unknown operation is happening here. Thanks in advance. asked 25 May '14, 00:41 149●2●7●14 accept rate: 9%

 1 It is rather strange. Codechef and Ideone run on the same SPOJ server so i do not understand why this problem is happening. answered 25 May '14, 01:18 3★kcahdog 10.0k●28●54●129 accept rate: 14% Actually I got TLE for the same solution(which got TLE in CODECHEF) in SPOJ also.. (25 May '14, 01:58) I think it has something to do with the version of C++ used. I think different versions must have caused the problem (25 May '14, 04:02) kcahdog3★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,901
×715
×630
×591
×10
×1
×1

question asked: 25 May '14, 00:41

question was seen: 1,939 times

last updated: 25 May '14, 04:02