ACM_java input/output optimization
Today's online competition is actually stuck in java's middleware... I am a beginner in java at sad. After the game, I read Daniel's statement. It turns out that I have optimized the input and output ....... Be drunk.
StreamTokenizer and PrintWriter
However, the use of tokens is as slow as cin. When the data volume times out, StreamTokenizer and PrintWriter must be used.
Import java. io. *; public class Main {public static void main (String [] args) throws IOException // in. nextTokenizer may throw this exception {StreamTokenizer in = new StreamTokenizer (new BufferedReader (new InputStreamReader (System. in); // This statement is packaged by the io stream. Remember it. PrintWriter out = new PrintWriter (new OutputStreamWriter (System. out); int a, B; while (in. nextToken ()! = StreamTokenizer. TT_EOF) // in. nextToken () reads the next tag, StreamTokenizer. TT_EOF is a parameter, that is, EOF {a = (int) in. nval; // The read type is double, so it must be converted to intin. nextToken (); // read the value B (the value of a is read in the while LOOP) B = (int) in. nval; out. println (a + B);} out. flush (); // required to refresh the buffer. Otherwise, a + B will stay in the buffer }}