【模板库】最强流读入

这是我见过的,最强的输入输出库
没有之一

namespace fastIO{
    #define BUF_SIZE 100000
    #define OUT_SIZE 100000
    #define ll long long
    //fread->read
    bool IOerror=0;
    inline char nc(){
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
        if (p1==pend){
            p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);
            if (pend==p1){IOerror=1;return -1;}
            //{printf("IO error!\n");system("pause");for (;;);exit(0);}
        }
        return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline void read(int &x){
        bool sign=0; char ch=nc(); x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
    }
    inline void read(ll &x){
        bool sign=0; char ch=nc(); x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
    }
    inline void read(double &x){
        bool sign=0; char ch=nc(); x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (ch=='.'){
            double tmp=1; ch=nc();
            for (;ch>='0'&&ch<='9';ch=nc())tmp/=10.0,x+=tmp*(ch-'0');
        }
        if (sign)x=-x;
    }
    inline void read(char *s){
        char ch=nc();
        for (;blank(ch);ch=nc());
        if (IOerror)return;
        for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch;
        *s=0;
    }
    inline void read(char &c){
        for (c=nc();blank(c);c=nc());
        if (IOerror){c=-1;return;}
    }
    //getchar->read
    inline void read1(int &x){
        char ch;int bo=0;x=0;
        for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
        for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
        if (bo)x=-x;
    }
    inline void read1(ll &x){
        char ch;int bo=0;x=0;
        for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
        for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
        if (bo)x=-x;
    }
    inline void read1(double &x){
        char ch;int bo=0;x=0;
        for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
        for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
        if (ch=='.'){
            double tmp=1;
            for (ch=getchar();ch>='0'&&ch<='9';tmp/=10.0,x+=tmp*(ch-'0'),ch=getchar());
        }
        if (bo)x=-x;
    }
    inline void read1(char *s){
        char ch=getchar();
        for (;blank(ch);ch=getchar());
        for (;!blank(ch);ch=getchar())*s++=ch;
        *s=0;
    }
    inline void read1(char &c){for (c=getchar();blank(c);c=getchar());}
    //scanf->read
    inline void read2(int &x){scanf("%d",&x);}
    inline void read2(ll &x){
        #ifdef _WIN32
            scanf("%I64d",&x);
        #else
        #ifdef __linux
            scanf("%lld",&x);
        #else
            puts("error:can't recognize the system!");
        #endif
        #endif
    }
    inline void read2(double &x){scanf("%lf",&x);}
    inline void read2(char *s){scanf("%s",s);}
    inline void read2(char &c){scanf(" %c",&c);}
    inline void readln2(char *s){gets(s);}
    //fwrite->write
    struct Ostream_fwrite{
        char *buf,*p1,*pend;
        Ostream_fwrite(){buf=new char[BUF_SIZE];p1=buf;pend=buf+BUF_SIZE;}
        void out(char ch){
            if (p1==pend){
                fwrite(buf,1,BUF_SIZE,stdout);p1=buf;
            }
            *p1++=ch;
        }
        void print(int x){
            static char s[15],*s1;s1=s;
            if (!x)*s1++='0';if (x<0)out('-'),x=-x;
            while(x)*s1++=x%10+'0',x/=10;
            while(s1--!=s)out(*s1);
        }
        void println(int x){
            static char s[15],*s1;s1=s;
            if (!x)*s1++='0';if (x<0)out('-'),x=-x;
            while(x)*s1++=x%10+'0',x/=10;
            while(s1--!=s)out(*s1); out('\n');
        }
        void print(ll x){
            static char s[25],*s1;s1=s;
            if (!x)*s1++='0';if (x<0)out('-'),x=-x;
            while(x)*s1++=x%10+'0',x/=10;
            while(s1--!=s)out(*s1);
        }
        void println(ll x){
            static char s[25],*s1;s1=s;
            if (!x)*s1++='0';if (x<0)out('-'),x=-x;
            while(x)*s1++=x%10+'0',x/=10;
            while(s1--!=s)out(*s1); out('\n');
        }
        void print(double x,int y){
            static ll mul[]={1,10,100,1000,10000,100000,1000000,10000000,100000000,
                1000000000,10000000000LL,100000000000LL,1000000000000LL,10000000000000LL,
                100000000000000LL,1000000000000000LL,10000000000000000LL,100000000000000000LL};
            if (x<-1e-12)out('-'),x=-x;x*=mul[y];
            ll x1=(ll)floor(x); if (x-floor(x)>=0.5)++x1;
            ll x2=x1/mul[y],x3=x1-x2*mul[y]; print(x2);
            if (y>0){out('.'); for (size_t i=1;i<y&&x3*mul[i]<mul[y];out('0'),++i); print(x3);}
        }
        void println(double x,int y){print(x,y);out('\n');}
        void print(char *s){while (*s)out(*s++);}
        void println(char *s){while (*s)out(*s++);out('\n');}
        void flush(){if (p1!=buf){fwrite(buf,1,p1-buf,stdout);p1=buf;}}
        ~Ostream_fwrite(){flush();}
    }Ostream;
    inline void print(int x){Ostream.print(x);}
    inline void println(int x){Ostream.println(x);}
    inline void print(char x){Ostream.out(x);}
    inline void println(char x){Ostream.out(x);Ostream.out('\n');}
    inline void print(ll x){Ostream.print(x);}
    inline void println(ll x){Ostream.println(x);}
    inline void print(double x,int y){Ostream.print(x,y);}
    inline void println(double x,int y){Ostream.println(x,y);}
    inline void print(char *s){Ostream.print(s);}
    inline void println(char *s){Ostream.println(s);}
    inline void println(){Ostream.out('\n');}
    inline void flush(){Ostream.flush();}
    //puts->write
    char Out[OUT_SIZE],*o=Out;
    inline void print1(int x){
        static char buf[15];
        char *p1=buf;if (!x)*p1++='0';if (x<0)*o++='-',x=-x;
        while(x)*p1++=x%10+'0',x/=10;
        while(p1--!=buf)*o++=*p1;
    }
    inline void println1(int x){print1(x);*o++='\n';}
    inline void print1(ll x){
        static char buf[25];
        char *p1=buf;if (!x)*p1++='0';if (x<0)*o++='-',x=-x;
        while(x)*p1++=x%10+'0',x/=10;
        while(p1--!=buf)*o++=*p1;
    }
    inline void println1(ll x){print1(x);*o++='\n';}
    inline void print1(char c){*o++=c;}
    inline void println1(char c){*o++=c;*o++='\n';}
    inline void print1(char *s){while (*s)*o++=*s++;}
    inline void println1(char *s){print1(s);*o++='\n';}
    inline void println1(){*o++='\n';}
    inline void flush1(){if (o!=Out){if (*(o-1)=='\n')*--o=0;puts(Out);}}
    struct puts_write{
        ~puts_write(){flush1();}
    }_puts;
    inline void print2(int x){printf("%d",x);}
    inline void println2(int x){printf("%d\n",x);}
    inline void print2(char x){printf("%c",x);}
    inline void println2(char x){printf("%c\n",x);}
    inline void print2(ll x){
        #ifdef _WIN32
            printf("%I64d",x);
        #else
        #ifdef __linux
            printf("%lld",x);
        #else
            puts("error:can't recognize the system!");
        #endif
        #endif
    }
    inline void println2(ll x){print2(x);printf("\n");}
    inline void println2(){printf("\n");}
    #undef ll
    #undef OUT_SIZE
    #undef BUF_SIZE
};

看了这份代码以后,我觉得一切语言都是苍白的

—————————— UPD 2017.7.5 ——————————
日常卡常用的话,用下面这份代码就好

inline char Read(){
    static const int BUF_SIZE = 1000000; 
    static char buf[BUF_SIZE], *p1 = 0, *p2 = 0;
    if (p1 == p2){
		p2 = (p1 = buf) + fread(buf, 1, BUF_SIZE, stdin);
    } 
	return p1 == p2? -1: *p1++;
} 
 
inline int read() {
	char c = Read(); int ret = 0, f = 1;
	for (; c < '0' || c > '9'; f = c == '-'? -1: 1, c = Read());
	for (; '0' <= c && c <= '9'; ret = ret * 10 + c - '0', c = Read());
	return ret * f;
}

89 thoughts to “【模板库】最强流读入”

  1. Hey would you mind letting me know which web host you’re working with?
    I’ve loaded your blog in 3 different web browsers and I must say this blog loads
    a lot quicker then most. Can you suggest a good web hosting
    provider at a reasonable price? Thanks, I appreciate it!

  2. Greetings! Quick question that’s completely off topic.
    Do you know how to make your site mobile friendly? My web site looks weird
    when browsing from my iphone4. I’m trying to find a template or plugin that might be able to correct this problem.
    If you have any suggestions, please share. Cheers!

  3. A fascinating discussion is definitely worth comment.

    I do think that you need to write more on this subject, it may not be a taboo subject but typically people do not speak about such
    issues. To the next! Kind regards!!

  4. I know this if off topic but I’m looking into starting my own weblog and was
    curious what all is required to get setup?
    I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very internet savvy so I’m not 100% sure. Any recommendations or
    advice would be greatly appreciated. Kudos

  5. Very nice post. I simply stumbled upon your blog and wished to
    say that I have really enjoyed browsing your weblog posts.

    In any case I will be subscribing on your rss feed
    and I hope you write once more very soon!

  6. My coder is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using WordPress on various websites for about a
    year and am nervous about switching to another platform.

    I have heard good things about blogengine.net. Is there
    a way I can transfer all my wordpress posts into it? Any kind of help would be really appreciated!

  7. I am now not certain where you are getting your information, however great
    topic. I needs to spend some time learning more or understanding more.
    Thank you for fantastic info I was in search of
    this information for my mission.

  8. A fascinating discussion is definitely worth
    comment. I think that you need to write more about this
    subject matter, it may not be a taboo subject but generally people
    don’t discuss such subjects. To the next! All the best!!

  9. I was recommended this blog via my cousin. I’m no longer positive whether or not this post is written by means of him
    as nobody else recognise such detailed approximately
    my problem. You are amazing! Thank you!

  10. Its such as you learn my thoughts! You appear to know so much about this,
    such as you wrote the e book in it or something.

    I think that you could do with some % to force the message house
    a bit, however other than that, this is fantastic blog.
    An excellent read. I’ll certainly be back.

  11. My brother recommended I may like this website.

    He was once entirely right. This post actually made my day.

    You cann’t consider simply how so much time I had spent for this info!
    Thank you! pof natalielise

  12. I feel that is one of the most significant information for
    me. And i am glad reading your article. But want to commentary on some normal issues, The web site style is
    ideal, the articles is actually excellent :
    D. Just right process, cheers

  13. Aw, this was a very nice post. Finding the time and actual effort to
    create a very good article… but what can I say… I procrastinate
    a whole lot and never manage to get anything done.

  14. Good day! This post couldn’t be written any better!
    Reading through this post reminds me of my old room mate!
    He always kept talking about this. I will forward this post to
    him. Fairly certain he will have a good read. Thanks
    for sharing!

  15. You could certainly see your skills in the work you write.
    The arena hopes for more passionate writers such as you who are not
    afraid to mention how they believe. All the time go after your
    heart.

  16. I’m not sure the place you’re getting your info, but great topic.

    I needs to spend a while learning much more or working out more.
    Thank you for fantastic info I was looking for this information for my mission.

  17. I was suggested this blog by means of my cousin.
    I’m no longer certain whether this post is written by him as
    nobody else recognise such particular approximately my difficulty.

    You are incredible! Thanks!

  18. Wonderful post however , I was wanting to know if you could
    write a litte more on this topic? I’d be very thankful if you could elaborate a little bit more.
    Appreciate it!

  19. You’re so cool! I do not think I’ve truly read through something like that before.
    So wonderful to discover someone with genuine thoughts on this topic.

    Seriously.. many thanks for starting this up. This web site is
    something that is required on the internet, someone with a bit of
    originality!

  20. It is really a great and useful piece of information. I am satisfied that you shared this useful information with us.
    Please keep us up to date like this. Thank you for sharing.

  21. Wonderful beat ! I would like to apprentice while you amend your site, how can i subscribe
    for a blog website? The account aided me a acceptable deal.

    I had been tiny bit acquainted of this your broadcast
    offered bright clear concept

  22. Heya i am for the first time here. I found this board and I find
    It truly useful & it helped me out much. I am hoping to
    offer something back and aid others like you helped me.

  23. I know this if off topic but I’m looking into starting my own blog and was wondering what all is
    needed to get setup? I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very web savvy so I’m not 100% sure.
    Any recommendations or advice would be greatly appreciated.
    Appreciate it

  24. I think this is among the most important information for me.
    And i am glad reading your article. But wanna remark on few general things, The website style is perfect,
    the articles is really great : D. Good job, cheers

  25. Magnificent goods from you, man. I’ve understand your stuff previous
    to and you’re just extremely magnificent. I really like what you’ve acquired here,
    really like what you are saying and the way in which you say
    it. You make it entertaining and you still care for to keep it sensible.
    I cant wait to read far more from you. This is
    actually a wonderful website.

  26. I loved as much as you’ll receive carried out right here.
    The sketch is tasteful, your authored subject matter stylish.
    nonetheless, you command get bought an shakiness over that you wish be delivering the following.
    unwell unquestionably come more formerly again as exactly the
    same nearly a lot often inside case you shield this hike.

  27. I’m now not positive the place you are getting your information, however great topic.
    I needs to spend some time finding out much more or figuring out more.
    Thank you for fantastic info I was in search of this info for my mission.

  28. I loved as much as you’ll receive carried
    out right here. The sketch is tasteful, your authored subject matter
    stylish. nonetheless, you command get got an shakiness over
    that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the
    same nearly a lot often inside case you shield
    this hike.

  29. Magnificent beat ! I wish to apprentice while you amend your website, how could
    i subscribe for a weblog website? The account helped
    me a applicable deal. I have been tiny bit acquainted of
    this your broadcast provided shiny clear idea

  30. Excellent post. I used to be checking constantly this blog and I am
    inspired! Extremely useful info particularly the remaining part 🙂 I care for such information a
    lot. I used to be looking for this certain information for a long time.
    Thanks and good luck.

  31. I have been browsing online more than three hours lately, yet I by no means found
    any attention-grabbing article like yours.
    It’s beautiful value sufficient for me. In my opinion, if
    all site owners and bloggers made just right content material as you probably did, the internet will be a lot more helpful than ever before.

  32. of course like your web site but you need to check the
    spelling on several of your posts. A number of them are
    rife with spelling issues and I to find it very
    troublesome to inform the reality nevertheless I
    will surely come again again.

  33. Hi my loved one! I want to say that this post is
    amazing, nice written and come with almost all significant infos.
    I would like to look more posts like this .

  34. Hi there! Someone in my Myspace group shared this site with
    us so I came to look it over. I’m definitely enjoying the information. I’m book-marking and will be tweeting this to my followers!
    Fantastic blog and superb design.

  35. Please let me know if you’re looking for a article writer for your weblog.
    You have some really good posts and I believe I would be
    a good asset. If you ever want to take some of the load off,
    I’d really like to write some articles for your blog in exchange for a link back to mine.
    Please send me an e-mail if interested. Cheers!

  36. I have been exploring for a little for any high quality articles or blog
    posts in this sort of area . Exploring in Yahoo I eventually stumbled upon this website.
    Reading this information So i am satisfied to express that
    I have a very good uncanny feeling I found out just what I needed.
    I so much undoubtedly will make sure to do not put out of your
    mind this web site and give it a glance regularly.

  37. magnificent post, very informative. I wonder why the other
    experts of this sector do not understand this. You must proceed your
    writing. I am confident, you have a huge readers’ base already!

  38. I know this if off topic but I’m looking into starting my own blog and was wondering what all is needed to get set
    up? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet savvy so I’m not 100% positive.

    Any suggestions or advice would be greatly appreciated.
    Appreciate it

  39. It’s truly very complicated in this full of activity life to listen news on Television, so I
    simply use web for that reason, and take the latest information.

  40. Hi there! This post couldn’t be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thank you for sharing!

  41. Excellent post. I was checking constantly this weblog and I’m impressed!
    Very useful information specially the ultimate phase :
    ) I handle such info a lot. I used to be seeking this particular info for a
    very long time. Thank you and good luck.

  42. Fantastic website. Plenty of helpful information here.

    I am sending it to some pals ans also sharing
    in delicious. And naturally, thanks to your sweat!

  43. Hello my loved one! I wish to say that this post is
    amazing, nice written and come with almost all important infos.
    I’d like to look more posts like this .

  44. Pretty nice post. I simply stumbled upon your blog and wished to say that I have truly loved browsing your blog
    posts. After all I will be subscribing for your feed and I’m hoping you write again very soon!

Leave a Reply

Your email address will not be published. Required fields are marked *