输入输出封装的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;
        }
    }
}


全部评论

相关推荐

暴杀流调参工作者:春招又试了一些岗位,现在投递很有意思,不仅要精心准备简历,投递官网还得把自己写的东西一条一条复制上去,阿里更是各个bu都有自己的官网,重复操作无数次,投完简历卡完学历了,又该写性格测评、能力测评,写完了又要写专业笔试,最近还有些公司搞了AI辅助编程笔试,有些还有AI面试,对着机器人话也听不明白录屏硬说,终于到了人工面试又要一二三四面,小组成员面主管面部门主管面hr面,次次都没出错机会,稍有不慎就是挂。 卡学历卡项目卡论文卡实习什么都卡,没有不卡的😂
点赞 评论 收藏
分享
04-01 12:25
中南大学 Java
枯基Evan_:腾讯一面写过11次的题目没写出来
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务