Last active
July 18, 2021 18:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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