快速输入输出模板

快速输入输出

indata() 输入函数
outdata()输出函数
在程序开头结尾调用。
ggt()返回0/1的opt
poread()整形读入
powrite()整形输出带换行

namespace nfdata
{
const int BS = 1 << 24;
const int SB = 1 << 22;
char buf[BS], *st, *ed;
char fub[SB], *bg = fub;
inline void indata()
{
    ed = buf + fread(st = buf, 1, BS, stdin);
}
inline void outdata()
{
    fwrite(fub, 1, bg - fub, stdout);
}
inline unsigned char ggt()
{
    register unsigned char x;
    while(!isdigit(x = (*st++)));
    return x == '1';
}
template <typename Y>
inline void poread(Y &res)
{
    register int ret = 0;
    char ch;
    while (!isdigit(ch = (*st++)))
        ;
    do
        ret = ret * 10 + ch - '0';
    while (isdigit(ch = (*st++)));
    res = ret;
}
template <typename T>
inline void powrite(T x)
{
    if(x < 10)
    {
        *bg++ = x + '0';
        *bg++ = '\n';
        return;
    }
    static char s[10];
    sprintf(s,"%d\n",x);
    memcpy(bg, s, sizeof(s));
    register int len = strlen(s);
    bg += len;
}
} // namespace nfdata
using nfdata::powrite;
using nfdata::poread;
using nfdata::ggt;

猜你喜欢

转载自www.cnblogs.com/Shiina-Rikka/p/11811811.html