码迷,mamicode.com
首页 > 编程语言 > 详细

Java读入优化

时间:2019-04-23 23:52:43      阅读:331      评论:0      收藏:0      [点我收藏+]

标签:write   writer   院校   readline   turn   cep   system.in   reader   inpu   

之前被软院校赛卡了一波T,很亏啊。以下抄袭自Codeforces的神仙Petr。
可能得系统研究Java怎么写了?

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class Solver {
        public void solve(InputReader in, PrintWriter out) {

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
    
}

Java读入优化

标签:write   writer   院校   readline   turn   cep   system.in   reader   inpu   

原文地址:https://www.cnblogs.com/Yinku/p/10759762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!