Advertisement
ivolff

govnina

Nov 20th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class MyScanner {
  7.  
  8.     private BufferedReader reader;
  9.  
  10.     public MyScanner( InputStream in ){
  11.         reader = new BufferedReader( new InputStreamReader( in ) );
  12.     }
  13.  
  14.     private String curString;
  15.  
  16.     Deque<Integer> ints = new LinkedList<Integer>();
  17.  
  18.     private String getCurString() throws IOException {
  19.         return reader.readLine();
  20.     }
  21.  
  22.     private boolean isNotDoubleCheck = true;
  23.     private boolean isNotDoubleInt = true;
  24.  
  25.     public boolean hasNextLine() throws IOException {
  26.         if( isNotDoubleCheck ){
  27.             curString = getCurString();
  28.         }
  29.         isNotDoubleCheck = false;
  30.         try {
  31.             return !curString.isEmpty();
  32.         } catch (NullPointerException ex){
  33.             return false;
  34.         }
  35.     }
  36.  
  37.  
  38.     public String nextLine() throws IOException {
  39.         if( hasNextLine() ){
  40.             isNotDoubleCheck = true;
  41.             return curString;
  42.         }
  43.         else{
  44.             isNotDoubleCheck = true;
  45.             throw new NoSuchElementException( "Next line not found" );
  46.         }
  47.  
  48.     }
  49.  
  50.     private void intIn()throws IOException {
  51.         curString = getCurString();
  52.         isNotDoubleInt=false;
  53.         String strArr[] = curString.split(" ");
  54.         int tmp;
  55.         for (int i = 0; i < strArr.length; i++) {
  56.             tmp= Integer.parseInt(strArr[i]);
  57.             ints.push(tmp);
  58.         }
  59.     }
  60.  
  61.     public boolean hasNextInt() throws IOException{
  62.         if(isNotDoubleInt)
  63.             intIn();
  64.         return !ints.isEmpty();
  65.     }
  66.  
  67.     public int nextInt() throws IOException{
  68.         if(isNotDoubleInt)
  69.             intIn();
  70.         if(hasNextInt())
  71.             return ints.pop();
  72.         else
  73.             throw new NoSuchElementException( "Next int not found" );
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement