首页 > 其他 > 详细

读入优化

时间:2019-10-24 22:02:24      阅读:90      评论:0      收藏:0      [点我收藏+]
  • fread 读入

有莫名其妙的问题,一般不用

技术分享图片
 1 inline char nc(){
 2     static char buf[100000],*p1=buf,*p2=buf;
 3     return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
 4 }
 5 inline int read(){
 6     char ch=nc();int sum=0;
 7     while(!(ch>=0&&ch<=9))ch=nc();
 8     while(ch>=0&&ch<=9)sum=sum*10+ch-48,ch=nc();
 9     return sum;
10 }
View Code
  • getc(stdio) 读入

用的最多

技术分享图片
inline void read(int &x)
{
    x = 0;int f = 1;char ch;
    ch = getc(stdin);
    while(ch > 9||ch < 0) {if(ch == -) f = -1;ch = getc(stdin);}
    while(ch <= 9&&ch >= 0) {x = (x * 10) + (ch ^ 48);ch = getc(stdin);}
    x *= f;
}
View Code

 

读入优化

原文:https://www.cnblogs.com/perigee/p/11734685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!