Skip to content

Instantly share code, notes, and snippets.

@jdabtieu
Last active July 18, 2021 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdabtieu/a3ec55a5345f063b08803c22d6780af5 to your computer and use it in GitHub Desktop.
Save jdabtieu/a3ec55a5345f063b08803c22d6780af5 to your computer and use it in GitHub Desktop.
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