Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Arrays;
- public class MyScanner {
- private Reader in = null;
- private int cur;
- public MyScanner(InputStream in) throws IOException {
- this.in = new BufferedReader(
- new InputStreamReader(
- in,
- "utf-8"
- ),
- 1024
- );
- this.cur = this.in.read();
- }
- public MyScanner(Reader in) throws IOException {
- this.in = in;
- this.cur = this.in.read();
- }
- public MyScanner(String str) throws IOException {
- this.in = new StringReader(str);
- this.cur = this.in.read();
- }
- public void close() {
- try {
- in.close();
- } catch (IOException e) {
- System.out.println("Error output" + e.getMessage());
- }
- }
- public String nextLine() throws IOException {
- StringBuilder buffer = new StringBuilder();
- //buffer.append(" ");
- while (getCurrent() != '\n' && !isEOF()) {
- buffer.append(getCurrent());
- skip();
- }
- skip();
- //skip();
- return new String(buffer);
- }
- public boolean hasNextLine() throws IOException {
- return !isEOF();
- }
- public void skip() throws IOException {
- cur = in.read();
- }
- public boolean isEOF() {
- return cur == -1;
- }
- public char getCurrent() {
- return (char) cur;
- }
- public boolean hasNextInt() throws IOException {
- while(getCurrent() != '\n' && !isEOF()) {
- if (Character.isDigit(getCurrent()) || getCurrent() == '-')
- return true;
- skip();
- }
- return false;
- }
- public int nextInt() throws IOException {
- StringBuilder buffer = new StringBuilder();
- while (Character.isDigit(getCurrent()) || getCurrent() == '-') {
- buffer.append(getCurrent());
- skip();
- }
- skip();
- return Integer.parseInt(buffer.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement