Commit 697475e8 authored by Chaigidel's avatar Chaigidel
Browse files

fix: 代码混乱

parent 10f315ac
Loading
Loading
Loading
Loading
+69 −59
Original line number Diff line number Diff line
@@ -214,16 +214,26 @@ c = read<__int128>();

## 完整带调试版

关闭调试开关时使用 `fread()`,  `fwrite()`,退出时自动析构执行 `fwrite()`

开启调试开关时使用 `getchar()`,  `putchar()`,便于调试。

```cpp
#define DEBUG 1  //调试开关
namespace IO {
#define isdigit(x) x >= '0' && x <= '9'
const int MAXSIZE = 1 << 20;
// #define DEBUG 1  //调试开关
struct IO {
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
    IO() : p1(buf), pp(pbuf) { p2 = buf + fread(buf, 1, MAXSIZE, stdin); }
    ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }
#endif
    inline char gc() {
#if DEBUG  //调试,可显示字符
        return getchar();
#endif
  static char buf[MAXSIZE], *p1 = buf + MAXSIZE, *p2 = buf + MAXSIZE;
        if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
        return p1 == p2 ? -1 : *p1++;
    }
@@ -238,9 +248,10 @@ inline void read(T &x) {
        register char ch = gc();
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
  for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0';
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - '0');
        if (ch == '.')
    for (ch = gc(); isdigit(ch); ch = gc()) tmp /= 10.0, x += tmp * (ch - 48);
            for (ch = gc(); isdigit(ch); ch = gc())
                tmp /= 10.0, x += tmp * (ch - '0');
        if (sign) x = -x;
    }
    inline void read(char *s) {
@@ -255,29 +266,28 @@ inline void read(char &c) {
            ;
    }
    inline void push(const char &c) {
  char pbuf[MAXSIZE], *pp = pbuf;
#if DEBUG  //调试,可显示字符
        putchar(c);
#else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
#endif
    }
    template <class T>
    inline void write(T x) {
        if (x < 0) x = -x, push('-');  // 负数输出
        static T sta[35];
        T top = 0;
        do {
            sta[top++] = x % 10, x /= 10;
        } while (x);
#if DEBUG  //调试,可显示字符
  while (top) putchar(sta[--top] + '0');
  return;
#endif
        while (top) push(sta[--top] + '0');
    }
    template <class T>
    inline void write(T x, char lastChar) {
  write(x), putchar(lastChar);  //打印末尾字符 ex.'\n'
        write(x), push(lastChar);
    }
}  // namespace IO
using namespace IO;
} io;
```

## 参考