• 快速读入快速输出


    快速读入

    一种写法:

    #define getchar() (p1 == p2 and (p2 = (p1 = buf) + fread(buf, 1, 1<<21, stdin), p1 == p2)? EOF : *p1++)
    
    long long read() {
    	long long x = 0, f = 1; char ch;
    	while(!isdigit(ch = getchar())) (ch == '-')and(f = -f);
    	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x<<1)+(x<<3)+(ch^48));
    	return x*f;
    }
    

    这种写法的缺陷在于仅可以用文件进行输入。但他确实是快啊qwq。

    另一种写法:

    template<typename temp>void read(temp &x){
    	x = 0;temp f = 1;char ch;
    	while(!isdigit(ch = getchar())) (ch == '-') and (f = -1);
    	for(x = ch^48; isdigit(ch = getchar()); x = (x<<1)+(x<<3)+(ch^48));
    	x *= f;
    }
    template <typename temp, typename ...Args>void read(temp& a, Args& ...args){read(a), read(args...);}
    
    

    特别方便,但用到了(C++11)里的语法。

    方便之处在于输入的时候你可以这样写:

    read(a, b, c, d, e);
    

    啊是的可以一次读入好几个数qwq。不用像这样:

    read(a), read(b), read(c);
    

    一次写好几个read()了。好方便的qwq。虽然在考试的时候没有办法用吧(雾。

    关于一个小地方:

    我有一次这样写快读:

    template<typename temp>temp read(temp &x){
    	x = 0;temp f = 1;char ch;
    	while(!isdigit(ch = getchar())) (ch == '-') and (f = -1);
    	for(x = ch^48; isdigit(ch = getchar()); x = (x<<1)+(x<<3)+(ch^48));
    	return(x *= f);
    }
    template <typename temp, typename ...Args>temp read(temp& a, Args& ...args){read(a), read(args...);}
    

    吸氧之后在某谷莫名RE(大雾??

    但是把这句代码中的

    template <typename temp, typename ...Args>temp read(temp& a, Args& ...args){read(a), read(args...);}
    

    temp改为原本模板中的void就对了,就蒟蒻本人也搞不懂,好像是我RE的写法不遵循某些语法,而(O_2)对语法的要求比较严格,但是快读的模板不加任何修改应该是没有问题的orz。

    以后还是乖乖写板子吧qaq。实在不行scanf也挺香的。

    快速输出

    然而并没有快速输出。他被鸽掉了。

  • 相关阅读:
    vue3.0 sync属性变化
    webRTC技术
    Vue3不支持eventBus
    远程连接MySQL数据库报错:is not allowed to connect to this MYSQL server的解决办法
    基于node.js实现前端web项目自动化部署
    SH 远程连接 Windows 服务器
    七牛云使用之配置域名CNAME
    基于python win32setpixel api 实现计算机图形学相关操作
    [JavaScript闭包]Javascript闭包的判别,作用和示例
    将exe程序添加到服务的命令
  • 原文地址:https://www.cnblogs.com/Vanyun/p/13382100.html
Copyright © 2020-2023  润新知