Fastio

好用的快读

快读 1 1 1

struct Fastio
{
    template <typename T>
    inline Fastio operator>>(T &x)
    {
        x = 0;
        char c = getchar();
        while (c < '0' || c > '9')
            c = getchar();
        while (c >= '0' && c <= '9')
            x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
        return *this;
    }
    template <typename T>
    inline Fastio operator>>(T &x)
    {
        x = 0;
        char c = getchar();
        while (c < '0' || c > '9')
            c = getchar();
        while (c >= '0' && c <= '9')
            x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
        return *this;
    }
} io;

快读 2 2 2

增加字符和字符串。

struct Fastio
{
    template <typename T>
    inline Fastio operator>>(T &x)
    {
        x = 0;
        char c = getchar();
        while (c < '0' || c > '9')
            c = getchar();
        while (c >= '0' && c <= '9')
            x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
        return *this;
    }
	inline Fastio &operator<<(const char c)
    {
        putchar(c);
        return *this;
    }
    inline Fastio &operator<<(const char *str)
    {
        int cur = 0;
        while (str[cur])putchar(str[cur++]);
        return *this;
    }
    template <typename T>
    inline Fastio &operator<<(T x)
    {
        if (x == 0)
        {
            putchar('0');
            return *this;
        }
        if (x < 0) putchar('-'), x = -x;
        static int sta[45];
        int top = 0;
        while (x) sta[++top] = x % 10, x /= 10;
        while (top) putchar(sta[top] + '0'), --top;
        return *this;
    }

} io;

快读 3 3 3

在快读 1 1 1 的基础上重定义 getchar()putchar()

namespace fastio
{
	int len = 0;
    char ibuf[(1 << 20) + 1], *iS, *iT, out[(1 << 23) + 1];
    #if ONLINE_JUDGE
    #define getchar() (iS == iT) ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
    int read()
    {
    	int x = 0, t = 0;
    	char c = getchar();
    	while(c < '0' || c > '9')
    	{
    		t |= ch == '-';
    		c = getchar();
		}
		while(c >= '0' && c <= '9')
		{
			x = (x << 3) + (x << 1) + (c ^ 48);
			c = getchar();
		}
		return t ? -x : x;
	}
	char getcA()
	{
		char c = getchar();
		while(c < 'A' || c > 'Z') c = getchar();
		return c;
	}
	char getca()
	{
		char c = getchar();
		while(c < 'a' || c > 'z') c = getchar();
		return c;
	}
	void putc(char c)
	{
		out[len++] = c;
	}
	void write(int x)
	{
		it(x < 0) putc('-'), x = -x;
		if(x > 9) write(x / 10);
		putc(x % 10 + 48);
	}
	struct af
	{
		~af()
		{
			fwrite(out, 1, len, stdout);
			len = 0;
		}
	}Af;
}

using namespace fastio;

快读 4 4 4

复杂度巨大。


/* --------------- fast io --------------- */ // begin
namespace Fastio
{
    namespace Fread
    {
        const int SIZE = 1 << 21;
        char buf[SIZE], *S, *T;
        inline char getchar()
        {
            if (S == T)
            {
                T = (S = buf) + fread(buf, 1, SIZE, stdin);
                if (S == T)
                    return '\n';
            }
            return *S++;
        }
    } // namespace Fread
    namespace Fwrite
    {
        const int SIZE = 1 << 21;
        char buf[SIZE], *S = buf, *T = buf + SIZE;
        inline void flush()
        {
            fwrite(buf, 1, S - buf, stdout);
            S = buf;
        }
        inline void putchar(char c)
        {
            *S++ = c;
            if (S == T)
                flush();
        }
        struct NTR
        {
            ~NTR() { flush(); }
        } ztr;
    } // namespace Fwrite
#ifdef ONLINE_JUDGE
#define getchar Fread ::getchar
#define putchar Fwrite ::putchar
#endif
    struct Reader
    {
        template <typename T>
        Reader &operator>>(T &x)
        {
            char c = getchar();
            T f = 1;
            while (c < '0' || c > '9')
            {
                if (c == '-')
                    f = -1;
                c = getchar();
            }
            x = 0;
            while (c >= '0' && c <= '9')
            {
                x = x * 10 + (c - '0');
                c = getchar();
            }
            x *= f;
            return *this;
        }
        Reader &operator>>(char &c)
        {
            c = getchar();
            while (c == ' ' || c == '\n')
            {
                c = getchar();
            }
            return *this;
        }
        Reader &operator>>(char *str)
        {
            int len = 0;
            char c = getchar();
            while (c == ' ' || c == '\n')
            {
                c = getchar();
            }
            while (c != ' ' && c != '\n' && c != '\r')
            { // \r\n in windows
                str[len++] = c;
                c = getchar();
            }
            str[len] = '\0';
            return *this;
        }
        Reader() {}
    } cin;
    const char endl = '\n';
    struct Writer
    {
        template <typename T>
        Writer &operator<<(T x)
        {
            if (x == 0)
            {
                putchar('0');
                return *this;
            }
            if (x < 0)
            {
                putchar('-');
                x = -x;
            }
            static int sta[111];
            int top = 0;
            while (x)
            {
                sta[++top] = x % 10;
                x /= 10;
            }
            while (top)
            {
                putchar(sta[top] + '0');
                --top;
            }
            return *this;
        }
        Writer &operator<<(char c)
        {
            putchar(c);
            return *this;
        }
        Writer &operator<<(char *str)
        {
            int cur = 0;
            while (str[cur])
                putchar(str[cur++]);
            return *this;
        }
        Writer &operator<<(const char *str)
        {
            int cur = 0;
            while (str[cur])
                putchar(str[cur++]);
            return *this;
        }
        Writer() {}
    } cout;
#define cin Fastio ::cin
#define cout Fastio ::cout
#define endl Fastio ::endl
} // namespace Fastio

/* --------------- fast io --------------- */ // end


快读 5 5 5

支持高精度运算和高精度快读,但不支持高精度位运算。



const int N = 1e4 + 5;
struct GJ
{
    int d[N];
    int len;
    void clean()
    {
        while (len > 1 && !d[len - 1])
            len--;
    }
    GJ()
    {
        memset(d, 0, sizeof d);
    }
    GJ(int num)
    {
        *this = num;
    }
    GJ(char *num)
    {
        *this = num;
    }
    GJ operator=(const char *num)
    {
        memset(d, 0, sizeof d);
        len = strlen(num);
        for (int i = 0; i < len; i++)
            d[i] = num[len - 1 - i] - '0';
        clean();
        return *this;
    }
    GJ operator=(int num)
    {
        char s[101];
        sprintf(s, "%d", num);
        *this = s;
        return *this;
    }
    GJ operator=(long long num)
    {
        char s[202];
        sprintf(s, "%lld", num);
        *this = s;
        return *this;
    }
    GJ operator=(string num)
    {
        memset(d, 0, sizeof d);
        len = num.length();
        for (int i = 0; i < len; i++)
            d[i] = num[len - 1 - i] - '0';
        clean();
        return *this;
    }
    GJ operator+(const GJ &b)
    {
        GJ c = *this;
        int i;
        for (i = 0; i < b.len; i++)
        {
            c.d[i] += b.d[i];
            if (c.d[i] > 9)
            {
                c.d[i] %= 10;
                c.d[i + 1]++;
            }
        }
        while (c.d[i] > 9)
        {
            c.d[i++] %= 10;
            c.d[i]++;
        }
        c.len = max(len, b.len);
        if (c.d[i] && c.len <= i)
            c.len = i + 1;
        return c;
    }
    GJ operator-(const GJ &b)
    {
        GJ c = *this;
        int i;
        for (i = 0; i < b.len; i++)
        {
            c.d[i] -= b.d[i];
            if (c.d[i] < 0)
            {
                c.d[i] += 10;
                c.d[i + 1]--;
            }
        }
        while (c.d[i] < 0)
        {
            c.d[i++] += 10;
            c.d[i]--;
        }
        c.clean();
        return c;
    }
    GJ operator*(const GJ &b) const
    {
        int i, j;
        GJ c;
        c.len = len + b.len;
        for (j = 0; j < b.len; j++)
            for (i = 0; i < len; i++)
                c.d[i + j] += d[i] * b.d[j];
        for (i = 0; i < c.len - 1; i++)
        {
            c.d[i + 1] += c.d[i] / 10;
            c.d[i] %= 10;
        }
        c.clean();
        return c;
    }
    GJ operator/(const GJ &b)
    {
        int i, j;
        GJ c = *this, a = 0;
        for (i = len - 1; i >= 0; i--)
        {
            a = a * 10 + d[i];
            for (j = 0; j < 10; j++)
            {
                if (a < b * (j + 1))
                    break;
            }
            c.d[i] = j;
            a = a - b * j;
        }
        c.clean();
        return c;
    }
    GJ operator%(const GJ &b)
    {
        int i, j;
        GJ a = 0;
        for (i = len - 1; i >= 0; i--)
        {
            a = a * 10 + d[i];
            for (j = 0; j < 10; j++)
            {
                if (a < b * (j + 1))
                    break;
            }
            a = a - b * j;
        }
        return a;
    }
    GJ operator+=(const GJ &b)
    {
        *this = *this + b;
        return *this;
    }
    GJ operator-=(const GJ &b)
    {
        *this = *this - b;
        return *this;
    }
    bool operator<(const GJ &b) const
    {
        if (len != b.len)
            return len < b.len;
        for (int i = len - 1; i >= 0; i--)
            if (d[i] != b.d[i])
                return d[i] < b.d[i];
        return false;
    }
    bool operator>(const GJ &b) const { return b < *this; }
    bool operator<=(const GJ &b) const { return !(b < *this); }
    bool operator>=(const GJ &b) const { return !(*this < b); }
    bool operator!=(const GJ &b) const { return b < *this || *this < b; }
    bool operator==(const GJ &b) const { return !(b < *this) && !(b > *this); }
    string str() const
    {
        char s[N] = {};
        for (int i = 0; i < len; i++)
            s[len - 1 - i] = d[i] + '0';
        return s;
    }
};
/* --------------- fast io --------------- */ // begin
namespace Fread
{
    const int SIZE = 1 << 21;
    char buf[SIZE], *S, *T;
    inline char getchar()
    {
        if (S == T)
        {
            T = (S = buf) + fread(buf, 1, SIZE, stdin);
            if (S == T)
                return '\n';
        }
        return *S++;
    }
} // namespace Fread
namespace Fwrite
{
    const int SIZE = 1 << 21;
    char buf[SIZE], *S = buf, *T = buf + SIZE;
    inline void flush()
    {
        fwrite(buf, 1, S - buf, stdout);
        S = buf;
    }
    inline void putchar(char c)
    {
        *S++ = c;
        if (S == T)
            flush();
    }
    struct NTR
    {
        ~NTR() { flush(); }
    } ztr;
} // namespace Fwrite
#ifdef ONLINE_JUDGE
#define getchar Fread ::getchar
#define putchar Fwrite ::putchar
#endif
namespace Fastio
{
    struct Doublee
    {
        double x;
        int k = 6;
    };
    struct Reader
    {
        template <typename T>
        Reader &operator>>(T &x)
        {
            char c = getchar();
            T f = 1;
            while (c < '0' || c > '9')
            {
                if (c == '-')
                    f = -1;
                c = getchar();
            }
            x = 0;
            while (c >= '0' && c <= '9')
            {
                x = x * 10 + (c - '0');
                c = getchar();
            }
            x *= f;
            return *this;
        }
        Reader &operator>>(double &num)
        {
            char in;
            double Dec = 0.1;
            bool IsN = false, IsD = false;
            in = getchar();
            if (in == EOF)
            {
                return *this;
            }
            while (in != '-' && in != '.' && (in < '0' || in > '9'))
            {
                in = getchar();
            }
            if (in == '-')
            {
                IsN = true;
                num = 0;
            }
            else if (in == '.')
            {
                IsD = true;
                num = 0;
            }
            else
            {
                num = in - '0';
            }
            if (!IsD)
            {
                while (in = getchar(), in >= '0' && in <= '9')
                {
                    num *= 10;
                    num += in - '0';
                }
            }
            if (in != '.')
            {
                if (IsN)
                    num = -num;
            }
            else
            {
                while (in = getchar(), in >= '0' && in <= '9')
                {
                    num += Dec * (in - '0');
                    Dec *= 0.1;
                }
            }
            if (IsN)
            {
                num = -num;
            }
        }
        Reader &operator>>(char &c)
        {
            c = getchar();
            while (c == ' ' || c == '\n')
            {
                c = getchar();
            }
            return *this;
        }
        Reader &operator>>(char *str)
        {
            int len = 0;
            char c = getchar();
            while (c == ' ' || c == '\n')
            {
                c = getchar();
            }
            while (c != ' ' && c != '\n' && c != '\r')
            { // \r\n in windows
                str[len++] = c;
                c = getchar();
            }
            str[len] = '\0';
            return *this;
        }
        Reader &operator>>(GJ &x)
        {
            string str = "";
            char c = getchar();
            while (c == ' ' || c == '\n')
            {
                c = getchar();
            }
            while (c != ' ' && c != '\n' && c != '\r')
            { // \r\n in windows
                str += c;
                c = getchar();
            }
            //cout << str.c_str();
            x = str.c_str();
            return *this;
        }
        Reader() {}
    } cin;
    const char endl = '\n';
    struct Writer
    {
        Writer &operator<<(Doublee op)
        {
            static int n = pow(10, op.k);
            if (op.x == 0)
            {
                putchar('0'), putchar('.');
                for (int i = 1; i <= op.k; ++i)
                    putchar('0');
                return *this;
            }
            if (op.x < 0)
                putchar('-'), op.x = -op.x;
            long long y = (long long)(op.x * n) % n;
            op.x = (long long)op.x;
            cout << op.x;
            putchar('.');
            int bit[10], p = 0, i;
            for (; p < op.k; y /= 10)
                bit[++p] = y % 10;
            for (i = p; i > 0; i--)
                putchar(bit[i] + 48);
            return *this;
        }
        template <typename T>
        Writer &operator<<(T x)
        {
            if (x == 0)
            {
                putchar('0');
                return *this;
            }
            if (x < 0)
            {
                putchar('-');
                x = -x;
            }
            static int sta[111];
            int top = 0;
            while (x)
            {
                sta[++top] = x % 10;
                x /= 10;
            }
            while (top)
            {
                putchar(sta[top] + '0');
                --top;
            }
            return *this;
        }
        Writer &operator<<(char c)
        {
            putchar(c);
            return *this;
        }
        Writer &operator<<(char *str)
        {
            int cur = 0;
            while (str[cur])
                putchar(str[cur++]);
            return *this;
        }
        Writer &operator<<(const char *str)
        {
            int cur = 0;
            while (str[cur])
                putchar(str[cur++]);
            return *this;
        }
        Writer &operator<<(const GJ &x)
        {
            string str = x.str();
            int cur = 0;
            while (str[cur])
                putchar(str[cur++]);
            return *this;
        }
        Writer() {}
    } cout;
} // namespace Fastio
#define cin Fastio ::cin
#define cout Fastio ::cout
#define endl Fastio ::endl

/* --------------- fast io --------------- */ // end
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值