How does Codechef test whether my solution is correct or not?

Your code is tested by a computer automatically, not by a human being, and you have to write your code accordingly.

For each problem, Codechef will have one or more input files, each according to the specifications mentioned in the problem statement, and corresponding correct output files. Codechef will run your program on each of the input files by redirecting the standard input stream to an input file, and the standard output stream to another file. The output generated by your program must match the correct output exactly in order to be judged correct.

Some consequences of this:

  • If your program starts by printing ‘Enter the number’ and the problem does not tell you to do so, then since this is not part of the correct output, you will be never be judged correct regardless of what the rest of your program does.

  • As all that matters is that the output files match, it makes no difference at all at what point in your program’s execution that this output is written. So there is no need to read all of the input before starting output; it is much more common to just print out each result as you are reading through the input.

  • If you use any method other than using the standard input and output streams - for example, using command line arguments, reading from a file, opening up some sort of dialog box, or otherwise - you will never be judged correct.

21 Likes