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

读入优化

时间:2019-10-24 21:46:26      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:eve   closed   opened   eof   static   pen   -o   text   span   

  • 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

 

读入优化

标签:eve   closed   opened   eof   static   pen   -o   text   span   

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

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