Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class FastestScanner {
- private InputStreamReader in;
- byte curByte = -2;
- public FastestScanner(InputStream stream) {
- in = new InputStreamReader(stream);
- }
- public boolean endOfStream() {
- return curByte == -1;
- }
- public void readByte() throws IOException {
- curByte = (byte) in.read();
- }
- public boolean endOfLine() {
- return curByte < 32;
- }
- public Integer nextInt() throws IOException {
- StringBuilder number = new StringBuilder(); int sign = 1;
- while (!endOfLine()) {
- if (curByte >= '0' && curByte <= '9' || curByte == '-') {
- break;
- }
- curByte = (byte) in.read();
- }
- if (curByte == '-') {
- sign = -1;
- curByte = (byte) in.read();
- }
- while (curByte >= '0' && curByte <= '9') {
- number.append((char) curByte);
- curByte = (byte) in.read();
- }
- if (number.length() == 0) {
- return null;
- } else {
- return sign * Integer.parseInt(number.toString());
- }
- }
- public void close() throws IOException {
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement