IO模板

把大概能用到的封装了一下。

反正都是没有用的东西。

#include<cmath>
#include<cstdio>
#include<cstring>
const int pcs=1000000;
double x;
struct io{
    char BuF[1<<26],*InF,WuF[1<<26];
    int OnF,st[10010];
    io():InF(BuF){
        freopen(".in","r",stdin);
        freopen(".out","w",stdout);
        fread(BuF,1,1<<26,stdin);
    }
    ~io(){
        fwrite(WuF,1,OnF,stdout);
        fclose(stdin);
        fclose(stdout);
    }
    template<typename T>void read(T &x){
        bool f=1;
        for(;47>*InF||*InF>58;f^=*InF++=='-');
        for(x=0;47<*InF&&*InF<58;x=x*10+(*InF++^48));
        if(*InF++=='.'){
            for(long double t=0.1;47<*InF&&*InF<58;x+=t*(*InF++-48),t/=10);
        }
        x=f?x:-x;
    }
    void read(char x){
        for(;*InF<33;InF++);
        x=*InF;
    }
    void read(char *x){
        int sz=0;
        for(read(x[0]);32<*InF;x[++sz]=*InF);
    }
    template<typename T>void write(T x){
        if(x<0){
            WuF[OnF++]='-';
            x=-x;
        }
        int t1=floor(x);
        double t2=x-t1;
        for(st[0]=0;t1;t1/=10){
            st[++st[0]]=t1%10+48;
        }
        for(;st[0];WuF[OnF++]=st[st[0]--]);
        if(t2){
            int z=round(t2*pcs);
            for(WuF[OnF++]='.';!(z%10);z/=10);
            write(z);
        }
    }
    void write(char x){
        WuF[OnF++]=x;
    }
    void write(char *x){
        for(int i=0,s=strlen(x);i<s;WuF[OnF++]=x[i++]);
    }
}io;
int main(){
    io.read(x);
    io.write(x);
}

原文地址:https://www.cnblogs.com/groundwater/p/14279711.html