zoukankan      html  css  js  c++  java
  • 快速读入快速输出

    快速读入

    一种写法:

    #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也挺香的。

    快速输出

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

  • 相关阅读:
    将文本文档数据导入excel,并生产折线
    worktile 查询已归档任务
    TestFlight下载app 初使用
    app测试之app启动时间计算
    MAC 鼠标没电了,键盘命令行关机
    git和adb安装及常用命令
    max 批量导入obj
    [水煮 ASP.NET Web API2 方法论](3-1)集中式路由
    [水煮 ASP.NET Web API2 方法论](12-4)OData 支持的 Function 和 Action
    [水煮 ASP.NET Web API2 方法论](12-3)OData 查询
  • 原文地址:https://www.cnblogs.com/Vanyun/p/13382100.html
Copyright © 2011-2022 走看看