Advertisement
unknown2433

FastInput

Dec 18th, 2021
123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. class FastInput {
  3. private static final int DEFAULT_BUFFER_SIZE = 1 << 16;
  4. private static final int MAX_CHAR_LEN_FOR_NEXT_LINE = 80;
  5. private static DataInputStream inputStream;
  6. private static byte[] buffer;
  7. private static int curIdx, maxIdx;
  8.  
  9. protected static void initFI() {
  10. inputStream = new DataInputStream(System.in);
  11. buffer = new byte[DEFAULT_BUFFER_SIZE];
  12. curIdx = maxIdx = 0;
  13. }
  14.  
  15. protected static int nextInt() throws IOException {
  16. int ret = 0;
  17. byte c = read();
  18. while (c <= ' ') c = read();
  19. boolean neg = (c == '-');
  20. if (neg) c = read();
  21. do {
  22. ret = ret * 10 + c - '0';
  23. } while ((c = read()) >= '0' && c <= '9');
  24. if (neg) return -ret;
  25. return ret;
  26. }
  27.  
  28. private static byte read() throws IOException {
  29. if (curIdx == maxIdx) {
  30. maxIdx = inputStream.read(buffer, curIdx = 0, DEFAULT_BUFFER_SIZE);
  31. if (maxIdx == -1) buffer[0] = -1;
  32. }
  33. return buffer[curIdx++];
  34. }
  35. }
  36.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement