输入输出封装的BufferReader模板


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

public class Main {
    static final int N = (int) (1e5 + 10), INF = 0x3f3f3f3f;
    // static int arr[] = new int[N];
    // static int arr[][] = new int[N][N];
    // static char g[][] = new char[N][N];
    // static boolean st[][] = new boolean[N][N];
    static int n, m, t;
    static int res, ans;

    static void solve() {
        // t = sc.nextInt();
        // while (t-- > 0) {
        while (sc.hasNext()) {
            

            out.flush();
        }
        out.flush();
    }

    static void solveCom() {
        solve();
        out.flush();
    }

    public static void main(String[] args) {
        solveCom();

        out.flush(); // 最后清空并关闭输出流
        out.close();
    }

    static PrintWriter out = new PrintWriter(System.out); // 输出流, 输出完之后记得用 out.flush() 清空一下缓存区
    static Reader sc = new Reader();

    static class Reader { // 封装快速读取类的方法(基于Scanner的方法来写)
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        boolean hasNext() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = br.readLine();
                    if (line == null) return false;
                    st = new StringTokenizer(line);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        }

        int nextInt() { return Integer.parseInt(next()); }

        long nextLong() { return Long.parseLong(next()); }

        double nextDouble() { return Double.parseDouble(next()); }

        String nextLine() {
            String line = null;
            try {
                line = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
    }
}


全部评论

相关推荐

黑皮白袜臭脚体育生:简历统一按使用了什么技术实现了什么功能解决了什么问题或提升了什么性能指标来写会更好另外宣传下自己的开源仿b站微服务项目,GitHub已经410star,牛客上有完整文档教程,如果觉得有帮助的话可以点个小星星,蟹蟹
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务