Last active
July 3, 2019 11:58
-
-
Save MinecraftFuns/16dd9e144b2fe79555e876a8cc05523c to your computer and use it in GitHub Desktop.
C++: FastIO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define FI(n) FastIO::read(n) | |
namespace FastIO | |
{ | |
const int SIZE = 1 << 16; | |
char buf[SIZE], obuf[SIZE], str[60]; | |
int bi = SIZE, bn = SIZE, opt; | |
int read(char *s) | |
{ | |
while (bn) | |
{ | |
for (; bi < bn && buf[bi] <= ' '; bi++) | |
; | |
if (bi < bn) | |
break; | |
bn = fread(buf, 1, SIZE, stdin); | |
bi = 0; | |
} | |
int sn = 0; | |
while (bn) | |
{ | |
for (; bi < bn && buf[bi] > ' '; bi++) | |
s[sn++] = buf[bi]; | |
if (bi < bn) | |
break; | |
bn = fread(buf, 1, SIZE, stdin); | |
bi = 0; | |
} | |
s[sn] = 0; | |
return sn; | |
} | |
bool read(int &x) | |
{ | |
int n = read(str), bf; | |
if (!n) | |
return 0; | |
int i = 0; | |
if (str[i] == '-') | |
bf = -1, i++; | |
else | |
bf = 1; | |
for (x = 0; i < n; i++) | |
x = x * 10 + str[i] - '0'; | |
if (bf < 0) | |
x = -x; | |
return 1; | |
} | |
}; // namespace FastIO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment