C++快速读写
oi
这个东西太常用了,单独贴出来吧。(虽然我个人认为这是玄学。)
别忘了 #include
1 2
| #include<cstdio> #include<cctype>
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| inline int read() { int X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| inline double dbread() { double X = 0, Y = 1.0; int w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) X = X * 10 + (ch ^ 48), ch = getchar(); ch = getchar(); while (isdigit(ch)) X += (Y /= 10) * (ch ^ 48), ch = getchar(); return w ? -X : X; }
|
1 2 3 4 5 6 7 8
| inline void write(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); }
|
其实我更喜欢这样
1 2
| ios::sync_with_stdio(false); cin.tie(0);
|