快读类

class Read {
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

    // 新增:判断是否还有输入,不消耗token,处理多组数据
    boolean hasNext() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = bf.readLine();
            // 输入流结束直接返回false,不会抛空指针
            if (line == null) return false;
            st = new StringTokenizer(line);
        }
        return true;
    }

    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException {
        return bf.readLine();
    }

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

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

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

按照我的模版解决即可:

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

public class Main {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();

    public static void main(String[] args) throws IOException {

        // 写代码

        out.close();
    }
}

class Read {
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

    // 新增:判断是否还有输入,不消耗token,处理多组数据
    boolean hasNext() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = bf.readLine();
            // 输入流结束直接返回false,不会抛空指针
            if (line == null) return false;
            st = new StringTokenizer(line);
        }
        return true;
    }

    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException {
        return bf.readLine();
    }

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

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

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

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐