SHARE
TWEET

Java I/O for competitive programming

a guest May 25th, 2014 261 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Input {
  5.     class $R {
  6.         InputStream in; byte b; byte[] buf; int bi, bz;
  7.         $R(InputStream I) { in=I; buf=new byte[65536]; bi=bz=0; read(); }
  8.         void skip() { while (b >= 0 && b <= 32) read(); }
  9.         void read() {
  10.             if (bi==bz) {
  11.                 bi=0; try { bz=in.read(buf); } catch(Exception e) { bz=-1; } }
  12.             b = bz == -1 ? -1 : buf[bi++];  }
  13.         // Optional methods
  14.         boolean hasNext() { skip(); return b >= 0; }
  15.         String next() {
  16.             StringBuilder sb = new StringBuilder();
  17.             for (skip(); b > 32; read()) sb.append((char)b);
  18.             return sb.length() == 0 ? null : sb.toString(); }
  19.         int nextInt() {
  20.             int i=0; boolean s=false; skip();
  21.             if (b == '-') { s=true; read(); }
  22.             for (; b > 32; read()) i = i*10 + b-48; return s ? -i : i; }
  23.         long nextLong() {
  24.             long i=0; boolean s=false; skip();
  25.             if (b == '-') { s=true; read(); }
  26.             for (; b > 32; read()) i = i*10 + b-48; return s ? -i : i; }
  27.         String nextLine() {
  28.             StringBuilder sb = new StringBuilder();
  29.             for (; b != 10 && b != 13; read()) sb.append((char)b);
  30.             while (b == 10 || b == 13) read(); return sb.toString(); }
  31.         String nextRealLine() {
  32.             StringBuilder sb = new StringBuilder();
  33.             for (; b != 10 && b != 13; read()) sb.append((char)b);
  34.             byte p = b; read();
  35.             if ((p == 10 && b == 13) || (p == 13 && b == 10)) read();
  36.             return sb.toString(); }
  37.     }
  38.     class $W extends PrintWriter {
  39.         $W() { super(new BufferedOutputStream(System.out)); }
  40.     }
  41.  
  42.     void run() {
  43.         $R $r = new $R(System.in);
  44.         $W $w = new $W();
  45.  
  46.         $w.close();
  47.     }
  48. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top