版本比较
快速读入
正文
增加 75 行删除 70 行
11 行未改动1213141516171617181920 行未改动4041424346474849505152535455565758444546474849505152535455566061626364656667686970575859606162636465666768697273747570767771798081828384858687888972737475769192937778798081828384858695969798998788899010110210310410510610710810911011111211311491929394959697989910010110210310410510611611711811912010710810911011111211311411511611711811912012112212312412512612712812913013113213313413511 行未改动PS:别问我为什么不写读入 `string` 的函数,因为要么慢要么容易越界,大家可以先读入 `char` 数组然后再用某些函数转换,或者根据题目数据范围自己写一个 `readString()`。
注意事项:
**最近代码有了较大更新,请仔细阅读注意事项。**
再次提醒:`read` 需要提供参数:要输入到的变量或数组元素
1. 这玩意儿输入的话不能和 scanf 和 cin 混用,不然会炸(手写缓冲区)。2. 输出同理,而且输出换行和空格分别用 `endline;` 和 `putc(' ')`20 行未改动
```cppnamespace IO { const int isiz = (1 << 20) + 1, osiz = (1 << 20) + 1; char ibuf[isiz]; char *iBegin = ibuf, *iEnd = ibuf; int len = 0; char outbuf[osiz]; inline char getc() { if (iBegin == iEnd) { iBegin = ibuf; iEnd = iBegin + fread(ibuf, 1, isiz, stdin); if (iBegin == iEnd) return EOF; } return *(iBegin++); return getchar();
const int isiz = (1 << 20) + 1, osiz = (1 << 20) + 1;char ibuf[isiz];char *iBegin = ibuf, *iEnd = ibuf;int len = 0;char outbuf[osiz];
inline char getc() { if (iBegin == iEnd) { iBegin = ibuf; iEnd = iBegin + fread(ibuf, 1, isiz, stdin); if (iBegin == iEnd) return EOF; } template<typename T> inline void read(T &x){ char ch = getc(); x = 0; bool t = 0; while (ch < '0' || ch > '9') { if (ch == EOF) return; if (ch == '-') { t = true; } ch = getc(); return *(iBegin++);}
template<typename T>inline void read(T &x){ char ch = getc(); x = 0; bool t = 0; while (ch < '0' || ch > '9') { if (ch == EOF) return; if (ch == '-') { t = true; } while (ch >= '0' && ch <= '9') { x *= 10; x += ch - '0'; ch = getc(); ch = getc(); } if (t) x = -x; } void readChars(char *s) { char ch = getc(); int len = 0; while (ch == ' ' || ch == '\n' || ch == '\r') { if (ch == EOF) break; else ch = getc(); } while (ch != ' ' && ch != '\n' && ch != '\r' && ch != -1) { s[len++] = ch; ch = getc(); } while (ch >= '0' && ch <= '9') { x *= 10; x += ch - '0'; ch = getc(); } void flush() { fwrite(outbuf, 1, len, stdout); len = 0; if (t) x = -x;}
void readChars(char *s) { char ch = getc(); int len = 0; while (ch == ' ' || ch == '\n' || ch == '\r') { if (ch == EOF) break; else ch = getc(); }#define endline putc('\n')#define space putc(' ') void putc(char ch) { outbuf[len++] = ch; if (len >= osiz - 1) flush(); while (ch != ' ' && ch != '\n' && ch != '\r' && ch != -1) { s[len++] = ch; ch = getc(); } template<typename T> void write(T x){ if (x == 0) { putc('0'); return; } if (x < 0) { putc('-'); x = -x; } if (x > 9) { write(x / 10); } putc(x % 10 + '0');}
void flush() { fwrite(outbuf, 1, len, stdout); len = 0;}void putc(char ch) { outbuf[len++] = ch; if (len >= osiz - 1) flush();}template<typename T>void write(T x){ if (x == 0) { putc('0'); return; } template<typename T> void writeString(T s, size_t len) { for (int i = 0; i < len; i++) { putc(s[i]); } if (x < 0) { putc('-'); x = -x; } if (x > 9) { write(x / 10); } putc(x % 10 + '0');}template<typename T>void writeString(T s, size_t len) { for (int i = 0; i < len; i++) { putc(s[i]); }}
#define endline putc('\n')#define space putc(' ')
}using IO::read;using IO::getc;using IO::readChars;using IO::flush;using IO::putc;using IO::write;using IO::writeString;
```