Does codechef give wrong answer if there is extra whitespace in output?

For example if say the question is print contents of an array of size 4 and do this:

for(int i=0;i<4;i++) {
cout<<A[i]<<" ";
}

So the output will be A[0] A[1] A[2] A[3]
and there should be a whitespace blank after A[3]

Solution to this would be to do this

for(int i=0;i<4;i++) {
   if(i==3) {
      cout<<A[i];
   }
   else {
      cout<<A[i]<<" ";
   }
}

but i was just wondering whether codechef treats these both as different or same?

(Probably outdated, some existing types of Judges are missing in the above link).

Codechef uses a Judge program to validate the output of the Submission. The most commonly used Judge is the one that \text{ignores extra white spaces} (self-explanatory). For some programs that ask you to print \text{any valid answer}, they use a custom Judge (basically a CPP Program running on the Server) that validates the Output.

1 Like

My experience is that an extra space on the end of a line does not prevent an answer from being accepted. Your code example

for(int i=0;i<4;i++) {
    cout<<A[i]<<" ";
}

will be accepted. I have no idea if extra space in the middle of a line of output matters.

2 Likes