Advertisement
Guest User

FastScanner

a guest
Dec 11th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. static class FastScanner {
  2.         BufferedReader br;
  3.         StringTokenizer st;
  4.  
  5.         public FastScanner(InputStream stream) {
  6.             br = new BufferedReader(new InputStreamReader(stream));
  7.             st = new StringTokenizer("");
  8.         }
  9.  
  10.         public FastScanner(String fileName) throws Exception {
  11.             br = new BufferedReader(new FileReader(new File(fileName)));
  12.             st = new StringTokenizer("");
  13.         }
  14.  
  15.         public String next() throws Exception {
  16.             while (!st.hasMoreTokens()) {
  17.                 st = new StringTokenizer(br.readLine());
  18.             }
  19.             return st.nextToken();
  20.         }
  21.  
  22.         public int nextInt() throws Exception {
  23.             return Integer.parseInt(next());
  24.         }
  25.  
  26.         public long nextLong() throws Exception {
  27.             return Long.parseLong(next());
  28.         }
  29.  
  30.         public Double nextDouble() throws Exception {
  31.             return Double.parseDouble(next());
  32.         }
  33.  
  34.         public String nextLine() throws Exception {
  35.             if (st.hasMoreTokens()) {
  36.                 StringBuilder str = new StringBuilder();
  37.                 boolean first = true;
  38.                 while (st.hasMoreTokens()) {
  39.                     if (first) {
  40.                         first = false;
  41.                     } else {
  42.                         str.append(" ");
  43.                     }
  44.                     str.append(st.nextToken());
  45.                 }
  46.                 return str.toString();
  47.             } else {
  48.                 return br.readLine();
  49.             }
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement