Advertisement
Guest User

Parser

a guest
Feb 20th, 2014
1,455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. class InputReader {
  2.     public:
  3.         InputReader() {}
  4.         InputReader(const char *file_name) {
  5.             input_file = fopen(file_name, "r");
  6.             cursor = 0;
  7.             fread(buffer, SIZE, 1, input_file);
  8.         }
  9.         inline InputReader &operator >>(int &n) {
  10.             while(buffer[cursor] < '0' || buffer[cursor] > '9') {
  11.                 advance();
  12.             }
  13.             n = 0;
  14.             while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
  15.                 n = n * 10 + buffer[cursor] - '0';
  16.                 advance();
  17.             }
  18.             return *this;
  19.         }
  20.     private:
  21.         FILE *input_file;
  22.         static const int SIZE = 1 << 17;
  23.         int cursor;
  24.         char buffer[SIZE];
  25.         inline void advance() {
  26.             ++ cursor;
  27.             if(cursor == SIZE) {
  28.                 cursor = 0;
  29.                 fread(buffer, SIZE, 1, input_file);
  30.             }
  31.         }
  32. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement