-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfast_io.cc
45 lines (45 loc) · 1.06 KB
/
fast_io.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <cstdio>
#include <cctype>
class FastIO {
int fd, bufsz;
char *buf, *cur, *end;
public:
FastIO(int _fd = 0, int _bufsz = 1 << 20) : fd(_fd), bufsz(_bufsz) {
buf = cur = end = new char[bufsz];
}
~FastIO() {
delete[] buf;
}
bool readbuf() {
cur = buf;
end = buf + bufsz;
while (true) {
size_t res = fread(cur, sizeof(char), end - cur, stdin);
if (res == 0) break;
cur += res;
}
end = cur;
cur = buf;
return buf != end;
}
int readint() {
while (true) {
if (cur == end) readbuf();
if (isdigit(*cur) || *cur == '-') break;
++cur;
}
bool sign = true;
if (*cur == '-') {
sign = false;
++cur;
}
int ret = 0;
while (true) {
if (cur == end && !readbuf()) break;
if (!isdigit(*cur)) break;
ret = ret * 10 + (*cur - '0');
++cur;
}
return sign ? ret : -ret;
}
};