Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.util.*;
- public class MyScanner {
- private BufferedReader reader;
- public MyScanner( InputStream in ){
- reader = new BufferedReader( new InputStreamReader( in ) );
- }
- private String curString;
- Deque<Integer> ints = new LinkedList<Integer>();
- private String getCurString() throws IOException {
- return reader.readLine();
- }
- private boolean isNotDoubleCheck = true;
- private boolean isNotDoubleInt = true;
- public boolean hasNextLine() throws IOException {
- if( isNotDoubleCheck ){
- curString = getCurString();
- }
- isNotDoubleCheck = false;
- try {
- return !curString.isEmpty();
- } catch (NullPointerException ex){
- return false;
- }
- }
- public String nextLine() throws IOException {
- if( hasNextLine() ){
- isNotDoubleCheck = true;
- return curString;
- }
- else{
- isNotDoubleCheck = true;
- throw new NoSuchElementException( "Next line not found" );
- }
- }
- private void intIn()throws IOException {
- curString = getCurString();
- isNotDoubleInt=false;
- String strArr[] = curString.split(" ");
- int tmp;
- for (int i = 0; i < strArr.length; i++) {
- tmp= Integer.parseInt(strArr[i]);
- ints.push(tmp);
- }
- }
- public boolean hasNextInt() throws IOException{
- if(isNotDoubleInt)
- intIn();
- return !ints.isEmpty();
- }
- public int nextInt() throws IOException{
- if(isNotDoubleInt)
- intIn();
- if(hasNextInt())
- return ints.pop();
- else
- throw new NoSuchElementException( "Next int not found" );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement