KSkun

fread template

Feb 21st, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. inline char fgc() {
  2.     static char buf[100000], *p1 = buf, *p2 = buf;
  3.     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
  4. }
  5.  
  6. inline LL readint() {
  7.     register LL res = 0, neg = 1;
  8.     char c = fgc();
  9.     while (c < '0' || c > '9') {
  10.         if(c == '-') neg = -1;
  11.         c = fgc();
  12.     }
  13.     while (c >= '0' && c <= '9') {
  14.         res = res * 10 + c - '0';
  15.         c = fgc();
  16.     }
  17.     return res * neg;
  18. }
  19.  
  20. inline double readdemi() {
  21.     register double res = 0;
  22.     register int siz = 0, neg = 1;
  23.     register bool indem = false;
  24.     char c = fgc();
  25.     while (c < '0' || c > '9') {
  26.         if(c == '-') neg = -1;
  27.         c = fgc();
  28.     }
  29.     while ((c >= '0' && c <= '9') || c == '.') {
  30.         if(c == '.') {
  31.             indem = true;
  32.             c = fgc();
  33.             continue;
  34.         }
  35.         if(indem) siz++;
  36.         res = res * 10 + c - '0';
  37.         c = fgc();
  38.     }
  39.     while(siz--) res /= 10;
  40.     return res * neg;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment