int快读

昨天偶然间看到CJ_tony的快读,所以便决定学习一下。

这个快读的原理就是:读入单个字符要比读入读入数字快,先读入字符,然后再转化成数字。(原理的话大学再研究)

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string> 
 4 #include<string>
 5 #include<iomanip>
 6 #include<cstdlib>
 7 using namespace std;
 8 int m,n;
 9 inline int read(){
10     char ch=getchar();
11     int f=1,x=0;
12     while(ch<'0'||ch>'9'){
13         if(ch=='-') f=-1;
14         ch=getchar();
15     }
16     while(ch>='0'&&ch<='9'){
17         x=(x<<1)+(x<<3)+ch-'0';
18         ch=getchar();
19     }
20     return f*x;
21 }
22 
23 int main(){
24     m=read(), n=read();
25     cout<<m<<" "<<n;    
26     return 0;
27 } 
待到oi十一月,我花开后百花杀。
原文地址:https://www.cnblogs.com/china-mjr/p/11271191.html