注意事项
读入注意这几点
- 如果关闭同步:ios::sync_with_stdio(false)
那么cin和scanf不能混用.且不能文件读入,- 不同系统下的longlong读入不一样.32位系统与64位系统longlong读入(或输出)时的格式不一样,32位系统下的读入(输出)是printf("%I64d,*x);
而64位的是scanf("%lld",&x);
而我们可以这样.
### scanf
ifdef WIN32
#define LL "%64d"
#else
#define LL "%lld"
#endif
读入(输出)的时候
直接scanf(LL,&x)
是不是很好用,当然我们完全可以使用cin,cout.(未关闭同步的cin,cout异常慢)
输入输出时间测试
1e7的数据 :cin 12.13
scanf 9.718
read 2.996
cout 20.91
printf 30.35
关闭同步后的cin 2.18
puts 1.47秒
不过我发现还是输入read,输出puts快.
以及具有非常快的速度的输入.时间是scanf的(1/10)
const int BUF_SIZE = 30;
char buf[BUF_SIZE], *buf_s = buf, *buf_t = buf + 1;
#define PTR_NEXT()
{
buf_s ++;
if (buf_s == buf_t)
{
buf_s = buf;
buf_t = buf + fread(buf, 1, BUF_SIZE, stdin);
}
}
#define readint(_n_)
{
while (*buf_s != '-' && !isdigit(*buf_s))
PTR_NEXT();
bool register _nega_ = false;
if (*buf_s == '-')
{
_nega_ = true;
PTR_NEXT();
}
int register _x_ = 0;
while (isdigit(*buf_s))
{
_x_ = _x_ * 10 + *buf_s - '0';
PTR_NEXT();
}
if (_nega_)
_x_ = -_x_;
(_n_) = (_x_);
}