Java 快读快写模板及读写示例(竞赛向)

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class fastRW {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StreamTokenizer st = new StreamTokenizer(br);
	static PrintWriter OUT = new PrintWriter(new BufferedOutputStream(System.out));

	public static int nextInt() throws Exception {
		st.nextToken();
		return (int) st.nval;
	}

	public static double nextDouble() throws Exception {
		st.nextToken();
		return st.nval;
	}

	public static String nextStr() throws Exception {
		st.nextToken();
		return st.sval;
	}

	public static String nextLine() throws Exception {
		return br.readLine();
	}

	public static void main(String[] args) throws Exception {
		readInt();
		// readStr();
		// readLine();
	}

	public static void readInt() throws Exception {
		// 读取整型数
		int n_int = nextInt();
		int list_int[] = new int[n_int];
		for (int i = 0; i < n_int; i++) {
			list_int[i] = nextInt();
		}
		for (int i = 0; i < n_int; i++) {
			OUT.println(list_int[i]);
		}
		OUT.flush();
	}

	public static void readStr() throws Exception {
		// 读取字符串
		int n_str = nextInt();
		String list_str[] = new String[n_str];
		for (int i = 0; i < n_str; i++) {
			list_str[i] = nextStr();
		}
		for (int i = 0; i < n_str; i++) {
			OUT.println(list_str[i]);
		}
		OUT.flush();
	}

	public static void readLine() throws Exception {
		// 读取下一行
		int n_line = nextInt();
		br.readLine();// 只读了第一行中的数字,要把第一行空出去
		String list_line[] = new String[n_line];
		for (int i = 0; i < n_line; i++) {
			list_line[i] = nextLine();
		}
		for (int i = 0; i < n_line; i++) {
			OUT.println(list_line[i]);
		}
		OUT.flush();
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值