C++快读

写在前面:

  一个小专题

  完全非原创,不知道原来是谁提出的

  诈尸

http://thepingaslord.deviantart.com/art/The-Evening-Prior-312446336


  • FR0X01
 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int a,b;
 6 double c,d;
 7 
 8 void readint(int &x){
 9     x=0;int neg=1;
10     char c=getchar();
11     while(c<'0'||c>'9'){
12         if(c=='-') neg=-1;
13         c=getchar();
14     }
15     while(c>='0'&&c<='9'){
16         x=10*x+c-'0';
17         c=getchar();
18     }
19     x*=neg;
20     return;
21 }
22 
23 void read(double &x){
24     x=0;double y=0.1,neg=1.0;
25     char c=getchar();
26     while(c<'0'||c>'9'){
27         if(c=='-') neg=-1.0;
28         c=getchar();
29     }
30     while(c>='0'&&c<='9'){
31         x=10*x+c-'0';
32         c=getchar();
33     }
34     if(c=='.'){
35         c=getchar();
36         while(c>='0'&&c<='9'){
37             x+=y*(c-'0');
38             y/=10;
39             c=getchar();
40         }
41     }
42     x*=neg;
43     return;
44 }
45 
46 int main()
47 {
48     readint(a);readint(b);
49     read(c);read(d);
50     
51     printf("%d
%d
",a,b);
52     printf("%lf
%lf
",c,d);
53     
54     return 0;
55 }
  • FR0X02不定长度
#include<bits/stdc++.h>

using namespace std;

char getint(int &x){
    x=0;int neg=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-') neg=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        x=10*x+c-'0';
        c=getchar();
    }
    x=x*neg;
    return c;
}

int main()//利用快读读不定个数 
{
    int x,y,w;
    for(int i=1;i<=3;++i)
    {
        char c;w=0;
        getint(x);c=getint(y);
        if(c!='
') getint(w);
        if(w) printf("%d %d %d
",x,y,w);
        else printf("%d %d
",x,y);
    }
    return 0;
}
  • AdvancedFR
 1 #include<iostream>
 2 #include<cstdio>
 3 
 4 using namespace std;
 5 
 6 inline char GC(){
 7     static char buf[100010],*p1=buf,*p2=buf;
 8     return (p1==p2&&(p2=(p1=buf)+fread(buf,1,100010,stdin),p1==p2))? EOF:*p1++;
 9 }
10 
11 void READ(int &x){
12     x=0;int neg=1;char c=GC();
13     while(c<'0'||c>'9'){if(c=='-')neg=-1;c=GC();}
14     while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c-'0');c=GC();}
15     x*=neg;
16 }
17 
18 int main(int arg,char *argv[],char *enc[])
19 {
20     freopen("game.in","r",stdin);freopen("game.out","w",stdout);
21     
22     fclose(stdin);fclose(stdout);
23     return 0;
24 }

(NOIP2018亲测能用)

例子:

 1 #include<bits/stdc++.h>
 2 #define reg register
 3 using namespace std;
 4 
 5 int U_Rarity;
 6 char E_Pie[10010];
 7 
 8 inline char GC(){
 9     static char buf[100010],*p1=buf,*p2=buf;
10     return (p1==p2&&(p2=(p1=buf)+fread(buf,1,100010,stdin),p1==p2))? EOF:*p1++;
11 }
12 
13 int main(int arg,char *argv[],char *enc[]){
14     freopen("winterwrapup.in","r",stdin);freopen("winterwrapup.out","w",stdout);
15     
16     int E_Pie_len=0;
17     for(reg int i=1;i<=10000;++i){
18         E_Pie[i]=GC();
19         ++E_Pie_len;
20         if(E_Pie[i]==10) break;
21     }
22     for(reg int i=1;i<=E_Pie_len;++i) printf("%c",E_Pie[i]);
23     printf("
Length:%d",E_Pie_len);
24     
25     fclose(stdin);fclose(stdout);
26     return 0;
27 }

比速度的话,AdvancedFR能够吊打基础快读

原文地址:https://www.cnblogs.com/Antigonae/p/11594715.html