快速读写

注意

  • 读入整数,类型包括int,long long,unsigned int,unsigned long long
  • 输出int等价于printf("%d",T);需要手动换行

使用方法

读入
Read(T);
输出
Out(T);

模板

int read()
{
    int x=0,f=1;
    char ch=getchar();
    while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x*f;
}

template <class T>
inline bool Read(T &ret)
{
    char c;int sgn;
    if(c=getchar(),c==EOF)    return 0;
    while(c!='-'&&(c<'0'||c>'9'))    c=getchar();
    sgn=(c=='-')?-1:1;ret=(c=='-')?0:(c -'0');
    while(c=getchar(),c>='0'&&c<='9')    ret=ret*10+(c-'0');
    ret*=sgn;
    return 1;
}

void Out(int a)
{
    if(a<0){putchar('-');a=-a;}
    if(a>=10)    Out(a/10);
    putchar(a%10+'0');
}

results matching ""

    No results matching ""