Quick read in Template
int read() { int s = 0, w = 1; char ch = getchar(); //getchar() 一次从键盘读入一个字符 while (ch <=‘0‘ || ch > ‘9‘) { if (ch == ‘-‘) w = -1; ch = getchar(); } while (ch >= ‘0‘ && ch <= ‘9‘) { s = s * 10 + ch - ‘0‘; ch = getchar(); } return s * w;}
Quick Output Template
inline void write(int x) { // inline 可以防止爆栈,虽然现在一般不太会 if (x < 0) putchar(‘-‘), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + ‘0‘);}
Register
Register is the meaning of the CPU register, the variables in this is much faster than in memory, so think of the variables in the following for
loop i
can be declared when the variable register
can be added to make the for
loop much faster. However, register
the space is very small, usually just a few megabytes, the server CPU may be larger. If the register is out of use, even if your variable is declared, register
it will not be placed in the register.
for (register int i = 1; i <= 1000000; ++i) { printf("%d\n", i);}
Kathang artifact--register with fast read-in output