zoukankan      html  css  js  c++  java
  • c++ 读入优化通用模板

    struct ioss
    {
      #define endl '
    '
        static const int LEN = 20000000;
        char obuf[LEN], *oh = obuf;
        std::streambuf *fb;
        ioss()
        {
            ios::sync_with_stdio(false);
            cin.tie(NULL);
            cout.tie(NULL);
            fb = cout.rdbuf();
        }
        inline char gc()
        {
    
            static char buf[LEN], *s, *t, buf2[LEN];
            return (s == t) && (t = (s = buf) + fread(buf, 1, LEN, stdin)), s == t ? -1 : *s++;
        }
        inline ioss &operator>>(long long &x)
        {
            static char ch, sgn, *p;
            ch = gc(), sgn = 0;
            for (; !isdigit(ch); ch = gc())
            {
                if (ch == -1)
                    return *this;
                sgn |= ch == '-';
            }
            for (x = 0; isdigit(ch); ch = gc())
                x = x * 10 + (ch ^ '0');
            sgn && (x = -x);
            return *this;
        }
        inline ioss &operator>>(int &x)
        {
            static char ch, sgn, *p;
            ch = gc(), sgn = 0;
            for (; !isdigit(ch); ch = gc())
            {
                if (ch == -1)
                    return *this;
                sgn |= ch == '-';
            }
            for (x = 0; isdigit(ch); ch = gc())
                x = x * 10 + (ch ^ '0');
            sgn && (x = -x);
            return *this;
        }
        inline ioss &operator>>(char &x)
        {
            static char ch;
            for (; !isalpha(ch); ch = gc())
            {
                if (ch == -1)
                    return *this;
            }
            x = ch;
            return *this;
        }
        inline ioss &operator>>(string &x)
        {
            static char ch, *p, buf2[LEN];
            for (; !isalpha(ch) && !isdigit(ch); ch = gc())
                if (ch == -1)
                    return *this;
            p = buf2;
            for (; isalpha(ch) || isdigit(ch); ch = gc())
                *p = ch, p++;
            *p = '';
            x = buf2;
            return *this;
        }
        inline ioss &operator<<(string &c)
        {
            for (auto &p : c)
                this->operator<<(p);
            return *this;
        }
        inline ioss &operator<<(const char *c)
        {
            while (*c != '')
            {
                this->operator<<(*c);
                c++;
            }
            return *this;
        }
        inline ioss &operator<<(const char &c)
        {
            oh == obuf + LEN ? (fb->sputn(obuf, LEN), oh = obuf) : 0;
            *oh++ = c;
            return *this;
        }
        inline ioss &operator<<(int x)
        {
            static int buf[30], cnt;
            if (x < 0)
                this->operator<<('-'), x = -x;
            if (x == 0)
                this->operator<<('0');
            for (cnt = 0; x; x /= 10)
                buf[++cnt] = x % 10 | 48;
            while (cnt)
                this->operator<<((char)buf[cnt--]);
            return *this;
        }
        inline ioss &operator<<(long long x)
        {
            static int buf[30], cnt;
            if (x < 0)
                this->operator<<('-'), x = -x;
            if (x == 0)
                this->operator<<('0');
            for (cnt = 0; x; x /= 10)
                buf[++cnt] = x % 10 | 48;
            while (cnt)
                this->operator<<((char)buf[cnt--]);
            return *this;
        }
        ~ioss()
        {
            fb->sputn(obuf, oh - obuf);
        }
    } io;

    使用:io>>x>>y; 即可

  • 相关阅读:
    2019-2020-1 20175214 《信息安全系统设计基础》第1周学习总结
    数据结构部分结构截图
    优化算法小结
    排序算法总结
    计算机网络复习总结(三)
    计算机网络复习总结(二)
    计算机网络复习总结(一)
    Spring mvc4 + ActiveMQ 整合
    JAVA中定时任务
    类上带泛型
  • 原文地址:https://www.cnblogs.com/FrankChen831X/p/11261146.html
Copyright © 2011-2022 走看看