Files
python/TangDou/CSP-J/J2-2021/快读快写.md
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

40 lines
850 B
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 快读快写
```c++
x << 1 == x * 2;
x << 3 == x * 2 * 2 * 2;
```
二者相加也就是 `x * 10`;
(1) 设$ch='3'$ $ASCII= 51 = 00110011(b)$
(2) 字符 $'0'$  $ASCII= 48 = 00110000(b)$
`^`运算规则:同$0$ 异$1$,相同的两个数异或为$0$ 不同的异或为$1$
`ch^48` 相当于 `ch -= '0'` ,得到 $00000011$,即数字$3$
```c++
//快读
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
//快写
inline void write(int x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
```