Fast reading

Fast reading

Don't ask why I wrote this quick reading, just to commemorate my crazy wa when I was useless quick reading!
Insert picture description here

Read int quickly

inline int IntRead()
{
    char ch = getchar();
    int s = 0, w = 1;
    while(ch < '0' || ch > '9')
    {
        if(ch == '-') w = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        s = s * 10 + ch - '0',
        ch = getchar();
    }
    return s * w;
}


Fast read string

inline string StringRead()
{
    string str;
    char s = getchar(); 
    while (s == ' ' || s == '\n' || s == '\r')
    {
        s = getchar();
    }
    while (s != ' ' && s != '\n' && s != '\r')
    {
        str += s;
        s = getchar();
    }
    return str;
}


Quickly read double

inline double DoubleRead()
{
    long long s = 0, w = 1, k = 0, n = 0, m = 0;
    char ch = getchar(); 
    while(ch < '0' || ch > '9')
    {
        if(ch == '-') w = -1;
        ch = getchar();
    }
    while((ch >= '0' && ch <= '9') || ch == '.')
    {
        if (ch == '.')
            n = 1;
        else if (n == 0)
            s = s * 10 + ch - '0';
           else k = k * 10 + ch - '0', m++;
        ch = getchar();
    }
    return (pow(0.1, m) * k + s) * w;
}

Instructions:

Just call this function directly and assign it to your variable. Don't think that fast reading is useless when the data is read one by one. It is really useful!

Guess you like

Origin blog.csdn.net/weixin_51216553/article/details/112037019
Recommended