Art_of_Programming_Contest_Part5

Art_of_Programming_Contest_Part5 - CHAPTER 5 INPUT/OUTPUT...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CHAPTER 5 INPUT/OUTPUT TECHNIQUES 83 The following is a slight modification to the code: char input[100],ch; void main(void) { freopen("input.txt","rb",stdin); scanf("%s\n",&input); scanf("%c",&ch); } What will be their value now? The value of ch will be '\n' for the first code and 'd' for the second code. Be careful about using gets() and scanf() together ! You should also be careful about using gets() and scanf() in the same program. Test it with the following scenario. The code is: scanf("%s\n",&dummy); gets(name); And the input file is: ABCDEF bbbbbXXX What do you get as the value of name? "XXX" or "bbbbbXXX" (Here, "b" means blank or space) Multiple input programs "Multiple input programs" are an invention of the online judge. The online judge often uses the problems and data that were first presented in live contests. Many solutions to problems presented in live contests take a single set of data, give the output for it, and terminate. This does not imply that the judges will give only a single set of data. The judges actually give multiple files as input one after another and compare the corresponding output files with the judge output. However, the Valladolid online judge gives only one file as input. It inserts all the judge inputs into a single file and at the top of that file, it writes how many sets of inputs there are. This number is the same as the number of input files the contest judges used. A blank line now separates each set of data. So the structure of the input file for multiple input program becomes:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CHAPTER 5 INPUT/OUTPUT TECHNIQUES 84 Integer N //denoting the number of sets of input --blank line--- input set 1 //As described in the problem statement --blank line--- input set 2 //As described in the problem statement --blank line--- input set 3 //As described in the problem statement --blank line--- . . . --blank line--- input set n //As described in the problem statement --end of file-- Note that there should be no blank after the last set of data. The structure of the output file for a multiple input program becomes: Output for set 1 //As described in the problem statement --Blank line--- Output for set 2 //As described in the problem statement --Blank line--- Output for set 3 //As described in the problem statement --Blank line--- . . . --blank line--- Output for set n //As described in the problem statement --end of file-- The USU online judge does not have multiple input programs like Valladolid. It prefers to give multiple files as input and sets a time limit for each set of input. Problems of multiple input programs There are some issues that you should consider differently for multiple input programs. Even if the input specification says that the input terminates with the end of file (EOF), each set of input is actually terminated by a blank line, except for the last one, which is terminated by the end of file. Also, be careful about the initialization of variables. If they are not properly initialized, your program may work for a single set of data but give correct
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 08/10/2011.

Page1 / 20

Art_of_Programming_Contest_Part5 - CHAPTER 5 INPUT/OUTPUT...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online