Note: The blogger continues to update this document until the end of the < to be continued > mark Clear
Enter the basic questions to consider
The algorithm competition topic usually has many test cases, uses the Redirect method to send the data to the program.
Then observe whether the output of the program is consistent with the expected results.
In most cases, these tests are present in the form of a file. This should be noted in the following questions:
- The data for each row has multiple items, and the delimiter is not fully determined, such as: one or more spaces.
- The number of data on each row may not be known. Continued until the end of the bank.
- A total number of lines may not be known, until the end of the file.
- The last line may not have a carriage return line break and will encounter EOF (file end tag) directly
- There may be different ways to line up under different operating systems.
- When a string is provided, it may contain spaces.
Let's cite some of the most common examples.
Several lines, one integer per line
Measured data
35-79
Because C + + 's class library is well-packaged, this can be handled concisely as follows:
#include <iostream>usingnamespace std;int main(){ int n; while(cin >> n){ cout << n << endl; } return0;}
On different platforms, the last line has no carriage return, the delimiter is 1 spaces or a number of spaces are well considered.
< to Be continued >
How to read data from standard input (2)--C + + language