Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. inline int readChar();
  2. template <class T = int> inline T readInt();
  3.  
  4. /** Read */
  5.  
  6. static const int buf_size = 4096;
  7.  
  8. inline int getChar() {
  9.     static char buf[buf_size];
  10.     static int len = 0, pos = 0;
  11.     if (pos == len)
  12.         pos = 0, len = fread(buf, 1, buf_size, stdin);
  13.     if (pos == len)
  14.         return -1;
  15.     return buf[pos++];
  16. }
  17.  
  18. inline int readChar() {
  19.     int c = getChar();
  20.     while (c <= 32)
  21.         c = getChar();
  22.     return c;
  23. }
  24.  
  25. template <class T>
  26. inline T readInt() {
  27.     int s = 1, c = readChar();
  28.     T x = 0;
  29.     if (c == '-')
  30.         s = -1, c = getChar();
  31.     while ('0' <= c && c <= '9')
  32.         x = x * 10 + c - '0', c = getChar();
  33.     return s == 1 ? x : -x;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement