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

输出读入优化——QAQ

时间:2017-08-19 14:22:11      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:tor   char   output   blog   sed   data   color   opera   flush   

技术分享
#include<bits/stdc++.h>
const int RN=1e5;
char ib[RN+5],*ip=ib+RN,ob[RN+1007],*op=ob;
inline int gc(){
    ip==ib+RN?fread(ip=ib,1,RN,stdin)[ib]=0:0;
    return*ip++;
}
struct IO{
    void flush(){
        fwrite(ob,1,op-ob,stdout),op=ob;
    }
    template<class T>//T=int,long long
    IO&operator>>(T&x0){
        T x=0;
        int f=1;
        if(ip<ib+RN-100){
            while(*ip<48)*ip++==-?f=-1:0;
            while(*ip>47)x=x*10+*ip++-48;
        }else{
            int c=gc();
            while(c<48)c==-?f=-1:0;
            while(c>47)x=x*10+c-48,c=gc();
        }
        x0=x;
        return *this;
    }
    IO&operator>>(char*s){
        int c=gc();
        while(c<33)c=gc();
        while(c>32)*s++=c,c=gc();
        *s=0;
        return *this;
    }
    template<class T>//T=int,long long,char
    IO&operator<<(T x){
        if(op>ob+RN)flush();
        int ss[25],sp=0;
        if(x<0)*op++=-,x=-x;
        do ss[++sp]=48+x%10;while(x/=10);
        while(sp)*op++=ss[sp--];
        return *this;
    }
    IO&operator<<(char x){
        if(op>ob+RN)flush();
        *op++=x;
        return *this;
    }
    IO&operator<<(const char*str){
        int n=strlen(str);
        if(op+n>ob+RN)flush();
        if(n<RN)memcpy(op,str,n),op+=n;
        else fwrite(str,1,n,stdout);
        return *this;
    }
    IO&operator<<(char*str){
        return *this<<(const char*)str;
    }
    IO&operator<<(std::string str){
        return *this<<str.data();
    }
}io;
int main(){
    freopen("in.txt","r",stdin);
    int a,b;
    io>>a>>b;
    io<<a<<+<<b<<=<<a+b<<\n;
    io<<"test_string_output\n";
    char s[111];
    io>>s;
    io<<s<<\n;
    io.flush();
    freopen("o.txt","w",stdout);
    for(int i=0;i<10000000;++i)io<<i<< ;
    io.flush();
    return 0;
}
View Code

 

输出读入优化——QAQ

标签:tor   char   output   blog   sed   data   color   opera   flush   

原文地址:http://www.cnblogs.com/lyzuikeai/p/7396242.html

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