ACM_java input/output optimization

Source: Internet
Author: User

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 }}


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.