From while (scanf ()! = EOF) Talking about the judging principle of ACM Onlinejuge

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.