×

 1 I tried to code the first question of easy section and it is saying time limit exceeded? what shall i do? here is my code: #include #include void main(void) { int c; int x=0; while (scanf("\n%d", &c)) { if(c == 42) { x=-1; } else { if(x== -1) {} else { printf("%d",c); } } } }  asked 15 Mar '12, 17:31 2★bhawnaj 16●2●2●3 accept rate: 0% 0★admin ♦♦ 19.8k●350●498●541

 3 Hello and welcome to Codechef. There are a few points which you must keep in mind while coding in Codechef (in C/C++): The main function should always return a zero. Otherwise the judge will return a Runtime error verdict. So your main function should be like this:  int main() { //Your code return 0; }  To take input till the end do the following:  while(scanf("\n%d", &c) != EOF) { //Your code }  EOF (Short for End Of File) is returned by scanf function when there is no more data in the file to be input. Print the output one line at a time:  printf("%d\n", c);  Putting it all together:  #include #include int main(void) { int c; int x=0; while (scanf("\n%d", &c) != EOF) { if(c == 42) { x=-1; } else { if(x== -1) {} else { printf("%d\n",c); } } } return 0; }  answered 15 Mar '12, 17:58 755●4●27●42 accept rate: 77% 1 Well that works but it is better to have a break statement after c==42 is tested true. If the input were designed to contain too many numbers after the first occurrence of 42 then it can be easily TLEd. Probably Codechef doesn't want to scare away newbies :) (15 Mar '12, 19:50) gultus ♦4★ @gultus I agree. But I wanted to make minimal changes to the original code. (16 Mar '12, 09:30)
 0 may 2017 Calendar may 2017 Calendar Printable YOUR ANSWER answered 06 Feb '17, 12:30 -83 accept rate: 0%
 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:

×720

question asked: 15 Mar '12, 17:31

question was seen: 1,780 times

last updated: 06 Feb '17, 12:30