Skip to content

Instantly share code, notes, and snippets.

@jdabtieu
Last active Jul 18, 2021
Embed
What would you like to do?
Java Fast IO (even faster than BufferedReader). Key differences: no thread safety, doesn't ensure that the input stream is still open, does not create unncessary objects
import java.io.InputStreamReader;
import java.io.IOException;
public class IO {
static InputStreamReader br = new InputStreamReader(System.in);
static char[] ibuf = new char[65536];
static int iptr = 0;
static int imax = 0;
static int readInt() throws IOException {
int x = 0;
char c;
while ((c = getChar()) <= ' ');
do {
x = x * 10 + (c - '0');
} while ((c = getChar()) > ' ');
return x;
}
static char getChar() throws IOException {
if (iptr >= imax) {
imax = br.read(ibuf, 0, 65536);
iptr = 0;
}
return ibuf[iptr++];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment