Preface
Before doing the curriculum design, inadvertently remembered to do the ACM topic commonly used line statement:
[CPP] view plain copy while (scanf ("%d", &a)! = EOF)
All of a sudden the effect of this sentence produced a curiosity, thought for a long while finally had a little result.
1. What is EOF?
EOF is a macro, and many functions (including scanf) return EOF when the read file is read to the end. [1]
2. while (scanf ()!=eof) flowchart
Let's take a look at the flowchart of the 3 loop statements you've learned before:
===================================================================================
①for Cycle
[CPP] view plain copy for (expression 1; expression 2; expression 3) {loop statement; }
②while Cycle
[CPP] view plain copy while (judgment statement) {Loop statement; }
③do-while Cycle
[CPP] view plain copy do {loop statement; }while (cyclic conditions);
===================================================================
Obviously while (scanf ("%d", &a)! = EOF) is not like any of the above flowchart,
So what is the flowchart of the while (scanf ("%d", &a)! = EOF).
It should be like this:
[CPP] view plain copy while (scanf ()! = EOF) {loop statement; }
3. The function of the statement when Onlinejuge is judged
The principle of OJ judgment should be this:
Input: With a pipeline command, a file containing several test cases is used as the "standard input stream", so the while (scanf ()! = EOF) is required to determine if the test file is read.
Output: the "standard output stream" is exported to a file via the pipeline command.
[CPP] view plain copy