is it necessary to write the output of all test cases together after scanning the input?
no.you can do it any way
1st-
input
output
input
output
2nd
input
input
input
output
output
output
This what really happens when you run a program on codechef:
-
It reads the input from an input text file.
-
It writes the output to another text file. The output statements in your program put some content on the console, here these output statements put this output in the output text file.
For example,
t=3;
for(i=0;i < t;i++)
{cin >> n;
cout << i << endl;
}
On console if you take input as n=100 for all n. This would have looked like:
100
0
100
1
100
2
OUTPUT FILE:
0
1
2
Now consider the code:
t=3
for(i=0;i < 3;i++)
cin>>n;
for(i=0;i < 3;i++)
cout << i << endl;
On console if you take input as n=100 for all n. This would have looked like:
100
100
100
0
1
2
OUTPUT FILE:
0
1
2
So you can clearly see that contents of the output file are the same in both the cases.
After generating these output files they are simply checked against the output correct files that are created by the problem setter.
You can also read the FAQ for more information.