码迷,mamicode.com
首页 > 其他好文 > 详细

信息学竞赛中的读入比较与其他读入方法

时间:2018-08-23 19:20:14      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:输入输出   不能   out   dig   目录   win32   pre   mat   注意   

目录

注意事项

读入注意这几点

  • 如果关闭同步: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_);     }

信息学竞赛中的读入比较与其他读入方法

标签:输入输出   不能   out   dig   目录   win32   pre   mat   注意   

原文地址:https://www.cnblogs.com/tpgzy/p/9525039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!