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

    快速输出

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

  • 相关阅读:
    一个合格的程序员应该读过哪些书
    一个程序员如何快速赚到一百万?
    如何创造财富?硅谷创业之父 Paul Graham 《黑客与画家》思维导图
    java 入门书籍(java7)
    活动预售和预热的目的
    活动策划
    店铺费率把控
    如何通过店铺数据分析店铺异常原因?
    刷单三大目的?如何安全、低成本、高效完成刷单
    活动报名技巧之——天天特卖
  • 原文地址:https://www.cnblogs.com/Vanyun/p/13382100.html
Copyright © 2011-2022 走看看