Mainly
在卡常(的时候,快速读入 & 输出非常有用,原理就是一位一位读入(输出)。80pts to 100pts
)
快速读入:
inline int read() {
char ch = getchar();
int x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * f;
}
用法示例:
n = read();
快速输出:
inline void write(int x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
用法示例:
write(n);
超级输入优化:
inline char nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}
inline void read(int &x) {
int f = 1;
x = 0;
char s = nc();
while (s < '0' || s > '9') {
if (s == '-') f = -1;
s = nc();
}
while (s >= '0' && s <= '9') {
x = x * 10 + s - '0';
s = nc();
}
x = x * f;
}
用法示例:
read(n);
超级输出优化:
char buf[100000], *pp = buf;
inline void pc(const char c) {
if (pp - buf == 100000) {
fwrite(buf, 1, 100000, stdout);
pp = buf;
}
*pp++ = c;
}
inline void write(int x) {
if (x < 0) {
pc('-');
x = -x;
}
if (x > 9) write(x / 10);
pc(x % 10 + '0');
}
inline void fsh() {
fwrite(buf, 1, pp - buf, stdout);
pp = buf;
}
用法示例:
write(n);
Article Author: XiaoHuang