Windows 中还有更优的快读快写模板吗?

学术版

ZHUSITAOcccccc @ 2024-09-19 21:28:06

快读:

inline int read() {
    register int x = 0, f = 1;
    register char c = getchar();
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (isdigit(c)) {
        x = (x << 1) + (x << 3) - (c ^ 48);
        c = getchar();
    }
    return x * f;
}

快写:

inline void write(int x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}

by zhanghm @ 2024-09-19 21:29:14

关闭同步流


by ikunTLE @ 2024-09-19 21:31:14

@ZHUSITAOcccccc 快写真的不快,不如 cout 关流/printf


by InQueue @ 2024-09-19 21:32:30

namespace Fread{
const long long 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 Fwrite{
    const long long 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;
} 
#ifdef ONLINE_JUDGE
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#endif
namespace Fastio{
    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){
            long long len=0;
            char c=getchar();
            while (c==' '||c=='\n'){
                c=getchar();
            }
            while (c!=' '&&c!='\n'&&c!='\r'){ 
                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 long long sta[45];
            long long 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){
            long long cur=0;
            while(str[cur]){
                putchar(str[cur++]);
            }
            return *this;
        }
        Writer& operator<<(const char* str){
            long long cur=0;
            while(str[cur]){
                putchar(str[cur++]);
            }
            return *this;
        }
        Writer(){}
    }cout;
}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl

by Caiest_Oier @ 2024-09-19 21:32:54

@ZHUSITAOcccccc 如果文件读写的话有个比getchar快一些的读法


by Caiest_Oier @ 2024-09-19 21:33:34

char *p1,*p2,buf[100000];
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
int read(){
    int x=0,f=1;
    char ch=nc();
    while(ch<48||ch>57){
        if(ch=='-')f=-1;
        ch=nc();
    }
    while(ch>=48&&ch<=57)x=x*10+ch-48,ch=nc();
    return x*f;
}

by zhanghm @ 2024-09-19 21:33:58

建议1e6以下用scanf/printf,1e6以上用关流 cin/cout


by ZHUSITAOcccccc @ 2024-09-19 21:40:00

@zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm @zhanghm

什么?

答非所问!


by lemoned_qwq @ 2024-09-19 21:40:43

@ZHUSITAOcccccc 快写可以直接printf 给我个关注吧


by ZHUSITAOcccccc @ 2024-09-19 21:40:59

@InQueue 对不起,我很菜,看不懂。


by ZHUSITAOcccccc @ 2024-09-19 21:41:28

@Caiest_Oier 对不起,我很菜,看不懂。


| 下一页