namespace IO {
const int maxn = 150960;
char buf[maxn], t[50];
int bn = maxn, bi = maxn;
int read(char *s) {
while (bn) {
for (; bi < bn && buf[bi] <= ' '; bi++);
if (bi < bn)break;
bn = fread(buf, 1, maxn, 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, maxn, stdin);
bi = 0;
}
s[sn] = 0;
return sn;
}
bool read(int &x) {
if (!read(t))return 0;
x = atoi(t);
return 1;
}
}
简短快乐强力输入挂:
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
char buf[(1 << 22)], *p1 = buf, *p2 = buf;
inline int read() {
char c = getchar();
int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}

本文介绍了一种在C++中实现快速输入输出的方法,通过自定义读取函数和利用缓冲区来提高IO效率,适用于竞赛编程和高性能计算场景。
1003

被折叠的 条评论
为什么被折叠?



