C++ 读入优化和输出优化

读入优化:

 

 1 #include<cctype>
 2 #define N 500010
 3 inline char gc()
 4 {
 5     static char buf[N],*p1=buf,*p2=buf;
 6     return p1==p2&&(p2=(p1=buf)+fread(buf,1,N,stdin),p1==p2)?EOF:*p1++;
 7 }
 8 inline void read(int &x)
 9 {
10     char ch=0;x=0;int f=0;
11     while (!isdigit(ch)) ch=gc(),f^=ch=='-';
12     while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
13     f&&(x=-x);
14 }

 

 

 

输出优化

1 inline void write(int x)
2 {
3     if (x<0) putchar('-'),x=-x;
4     if (x>9) write(x/10);
5     putchar(x%10+48);
6 }

 

原文链接: https://www.cnblogs.com/lsb20060209/p/12253057.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    C++ 读入优化和输出优化

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/326611

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月1日 下午3:54
下一篇 2023年3月1日 下午3:54

相关推荐