Advertisement
Guest User

Array based IntIO

a guest
Oct 25th, 2015
272
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ArrayIn
  2. {
  3.     final byte[] buf;
  4.     int rpos;
  5.  
  6.     public ArrayIn(final InputStream in, final int size) throws IOException
  7.     {
  8.         buf = new byte[size];
  9.         in.read(buf);
  10.     }
  11.     public int getInt() throws IOException
  12.     {
  13.         while(buf[rpos]<=' ') ++rpos;
  14.         int chr = buf[rpos++], sum = chr-'0';
  15.         while((chr = buf[rpos++])>' ') sum = (sum<<3)+sum+sum + chr-'0';
  16.         return sum;
  17.     }
  18. }
  19.  
  20.  
  21. // Usually initialized like this.
  22. final ArrayIn in = new ArrayIn(System.in, 1<<20),
Advertisement
RAW Paste Data Copied
Advertisement