zoukankan      html  css  js  c++  java
  • 输出读入优化——QAQ

    #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<<'
    ';
        io<<"test_string_output
    ";
        char s[111];
        io>>s;
        io<<s<<'
    ';
        io.flush();
        freopen("o.txt","w",stdout);
        for(int i=0;i<10000000;++i)io<<i<<' ';
        io.flush();
        return 0;
    }
    View Code
  • 相关阅读:
    HTML 之轮播图
    Django 框架之 URL
    Django 框架搭建入门案例
    Python 操作 MySQL
    Python 之RabbitMQ使用
    Python 之协程
    Python 之网络编程
    Python 序列化
    Python 装饰器
    python(3)-内置函数
  • 原文地址:https://www.cnblogs.com/lyzuikeai/p/7396242.html
Copyright © 2011-2022 走看看