The method of adding two fast read and write

1. The main function at the beginning of the following piece of code is added:

ios::sync_with_stdio(false);
cin.tie(0);

2. fast read and write
first introduced <cstdio> and <iostream> Both libraries
followed by addition of the following series of codes

using namespace std;
namespace fast_IO {
    inline int read() {
        int x=0,f=1;char ch=getchar();
        while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
        while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
        return x*f;
    }
    inline void write(int x) {a
        if(x < 0) {
            putchar('-');
            x = -x;
        }
        if(x > 9) write(x / 10);
        putchar(x % 10 + '0');
    }
};
using namespace fast_IO;

When you need to read data into a time:

a = read();

When you need a data output:

write(b);

When you need to output a space or a line break:

putchar(' '); 
putchar('\n');

On this basis, you can make your program to become fast

Released three original articles · won praise 4 · Views 151

Guess you like

Origin blog.csdn.net/qq_45836635/article/details/104083847