【模板】读入挂

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/IDrandom/article/details/81708882

普通读入挂

inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

简易加强读入挂
参考qscqesze大佬,简单判了下负数情况;
原文中有适应面更广的读入挂,欢迎去围观大佬的博客
原文链接

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int BUF=40000000;
char Buf[BUF],*buf=Buf;
const int OUT=20000000;
char Out[OUT],*ou=Out;int Outn[30],Outcnt;
inline void write(int x){
    if(!x)*ou++=48;
    else{
        if(x<0){*ou++=45;x=-x;}
        for(Outcnt=0;x;x/=10)Outn[++Outcnt]=x%10+48;
        while(Outcnt)*ou++=Outn[Outcnt--];
    }
}
inline void writell(LL x){
    if(!x)*ou++=48;
    else{
        if(x<0){*ou++=45;x=-x;}
        for(Outcnt=0;x;x/=10)Outn[++Outcnt]=x%10+48;
        while(Outcnt)*ou++=Outn[Outcnt--];
    }
}
inline void writechar(char x){*ou++=x;}
inline void writeln(){*ou++='\n';}
inline void read(int &a){int f;for(a=0,f=1;*buf<48;buf++){if(*buf==45)f=-1;};while(*buf>47)a=a*10+*buf++-48;a*=f;}
inline void read(LL &a){int f;for(a=0,f=1;*buf<48;buf++){if(*buf==45)f=-1;};while(*buf>47)a=a*10+*buf++-48;a*=f;}

int main(){
    fread(Buf,1,BUF,stdin);
    int a,b;
    read(a),read(b);
    write(a+b);
    writeln();
    fwrite(Out,1,ou-Out,stdout);
}

猜你喜欢

转载自blog.csdn.net/IDrandom/article/details/81708882