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
import java.util.*;import java.io.*;publicclass A{ publicstaticvoidmain(String[] args){ new Scanner(System.in); try{ while(true){ System.out.println("-> " + scan.nextInt()); } } catch(Exception e){} }}
In this way, it doesn't matter if the last line has a newline character.
Even the last number of empty lines is not a problem.
Several lines, two integers per line, separated by one or more spaces
Test data
10 2030 4050 60
import java.util.*;import java.io.*;publicclass B{ publicstaticvoidmain(String[] args){ new Scanner(System.in); try{ while(true){ System.out.println("-> " + scan.nextInt"," + scan.nextInt()); } } catch(Exception e){} }}
How to read data into--java language from standard input