SHARE
TWEET

Untitled

a guest Oct 16th, 2019 168 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.InputStreamReader;
  5. import java.util.InputMismatchException;
  6.  
  7. public  class FastScanner {
  8.     private BufferedReader br;
  9.     private int pos, len;
  10.     private char[] buffer = new char[4096];
  11.     private boolean EOF = false;
  12.     public FastScanner (InputStream is) {
  13.         br = new BufferedReader(new InputStreamReader(is));
  14.     }
  15.    // public FastScanner(String string)
  16.     private void readBuffer() throws IOException{
  17.         len = br.read(buffer);
  18.         while (len==0){
  19.             len = br.read(buffer);
  20.         }
  21.         if (len == -1)
  22.         {
  23.             EOF = true;
  24.         }
  25.         pos=0;
  26.     }
  27.     public char nextchar() throws IOException {
  28.         if (pos>=len){
  29.             readBuffer();
  30.         }
  31.         return buffer[pos++];
  32.     }
  33.  
  34.     public boolean hasNextChar() throws IOException{
  35.         nextchar();
  36.         pos--;
  37.         return !EOF;
  38.     }
  39.     public String readLine() throws IOException{
  40.         StringBuilder sb = new StringBuilder();
  41.         char c;
  42.         while(hasNextChar()){
  43.             c= nextchar();
  44.             if (c == '\n')
  45.             {
  46.                 break;
  47.             }
  48.             if (c != '\r') {
  49.                 sb.append(c);
  50.             }
  51.         }
  52.         return sb.toString();
  53.     }
  54.     public int nextInt() throws IOException {
  55.         skipBlank();
  56.         StringBuilder sb = new StringBuilder();
  57.         char c;
  58.         while (hasNextChar()){
  59.             c = nextchar();
  60.             if (Character.isDigit(c))
  61.             {
  62.                 sb.append(c);
  63.             }
  64.             else {
  65.                 if (!Character.isWhitespace(c))
  66.                 {
  67.                     throw new InputMismatchException("");
  68.                 }
  69.                 break;
  70.             }
  71.         }
  72.         try {
  73.             return Integer.parseInt(sb.toString());
  74.         } catch (NumberFormatException e) {
  75.             throw new InputMismatchException();
  76.         }
  77.     }
  78.     private void skipBlank() throws IOException{
  79.         while (true) {
  80.         if (!hasNextChar() || !Character.isWhitespace(nextchar())) break;
  81.     }
  82.         pos--;
  83.     }
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top