输入挂

简化版:(正int输入挂)

int read()
{
    char ch=' ';
    int ans=0;
    while(ch<'0' || ch>'9')
        ch=getchar();
    while(ch<='9' && ch>='0')
    {
        ans=ans*10+ch-'0';
        ch=getchar();
    }
    return ans;
}


inline void out(int x)
{
    if(x>9) out(x/10);
    putchar(x%10+'0');
}

 

int && long long && double 输入挂

template <class T>
bool scan_d(T &ret)
{
    char c;
    int sgn;
    T bit=0.1;
    if(c=getchar(), c==EOF)
        return 0;
    while(c!='-' && 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');
    if(c==' ' || c=='\n')
    {
        ret*=sgn;
        return 1;
    }
    while(c=getchar(), c>='0' && c<='9')
        ret+=(c-'0')*bit, bit/=10;
    ret*=sgn;
    return 1;
}

 

完整版高速输入挂(速度快于之前两个版本)

//-------------------输入挂
const int MAXBUF=10000;
char buf[MAXBUF],*ps = buf,*pe = buf+1;
inline void rnext()
{
    if(++ps==pe) pe=(ps=buf)+fread(buf,sizeof(char),sizeof(buf)/sizeof(char),stdin);
}
template<class T>
inline bool in(T &ans)
{
    ans=0;
    T f=1;
    if(ps==pe) return false;//EOF
    do
    {
        rnext();
        if('-' == *ps) f=-1;
    }while(!isdigit(*ps)&&ps!=pe);
    if(ps==pe) return false;//EOF
    do
    {
        ans=(ans<<1)+(ans<<3)+*ps-48;
        rnext();
    }while(isdigit(*ps)&&ps!=pe);
    ans*=f;
    return true;
}



//---------------输出挂

const int  MAXOUT=10000;
char bufout[MAXOUT],outtmp[50],*pout=bufout,*pend=bufout+MAXOUT;
inline void write()
{
    fwrite(bufout,sizeof(char),pout-bufout,stdout);
    pout=bufout;
}
inline void out_char(char c)
{
    *(pout++)=c;
    if(pout == pend) write();
}
inline void out_str(char *s)
{
    while(*s)
    {
        *(pout++)=*(s++);
        if(pout==pend) write();
    }
}
template <class T>
inline void out_int(T x)
{
    if(!x)
    {
        out_char('0');
        return;
    }
    if(x<0) x=-x,out_char('-');
    int len=0;
    while(x)
    {
        outtmp[len++]=x%10+48;
        x/=10;
    }
    outtmp[len]=0;
    for(int i=0, j=len-1;i<j;i++,j--) swap(outtmp[i],outtmp[j]);
    out_str(outtmp);
}


//---------------用法

int main()
{
    int t,ca=1;
    in(t);
    while(t--)
    {
        int n;
        in(n);
        out_str("Case #");
        out_int(ca++);
        out_str(": ");
        out_int(n);
        out_char('\n');
    }
    write(); //不可少~
    return 0;
}

 

posted @ 2016-01-25 10:43  蓦辰  阅读(147)  评论(0编辑  收藏  举报