码迷,mamicode.com
首页 > 其他好文 > 详细

输入输出优化模板

时间:2018-08-23 02:17:04      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:bool   while   utc   name   tchar   typename   输入   pre   code   

fread

char buf[1<<20],*p1,*p2;
inline char gc()
{
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin))==p1?0:*p1++;
}

输入

template<typename T>
void read(T &x)
{
    char tt;
    bool flag=0;
    while(!isdigit(tt=gc())&&tt!='-');
    tt=='-'?(x=0,flag=1):(x=tt-'0');
    while(isdigit(tt=gc())) x=x*10+tt-'0';
    if(flag) x=-x;
}

输出

template<typename T>
void write(T x,bool flag)
{
    if(x<0) putchar('-'),x=-x;
    if(!flag) putchar(x%10+'0');
    if(x>9) write(x/10,1),putchar(x%10+'0');
}

输入输出优化模板

标签:bool   while   utc   name   tchar   typename   输入   pre   code   

原文地址:https://www.cnblogs.com/KatouKatou/p/9521125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!