ACM Principles _ Input Hang

Source: Internet
Author: User

What is input hanging?

It is well known that scanf is much faster than CIN, so is there anything faster than scanf? The answer is that the input is hung, the input is used to tell the Read function GetChar (), and then manually processed into an integer or floating point, much faster than using scanf.

When do I use input to hang up?

When the input scale reaches 1x10^6, it is necessary to enter the hanging, otherwise it is likely to time out.

Code

The code is not written by me, here is the source: http://www.cnblogs.com/xiaohongmao/archive/2012/05/29/2523760.html

Integer
InlineBOOLScan_d (int&num) {        Char inch;BOOLisn=false; inch=GetChar (); if(inch==eof)return false;  while(inch!='-'&& (inch<'0'||inch>'9'))inch=GetChar (); if(inch=='-') {isn=true; num=0;} Elsenum=inch-'0';  while(inch=getchar (),inch>='0'&&inch<='9') {num*=Ten, num+=inch-'0'; }        if(IsN) num=-num; return true;}
Floating point
InlineBOOLSCAN_LF (Double&num) {        Char inch;DoubleDec=0.1; BOOLisn=false, isd=false; inch=GetChar (); if(inch==eof)return false;  while(inch!='-'&&inch!='.'&& (inch<'0'||inch>'9'))                inch=GetChar (); if(inch=='-') {isn=true; num=0;} Else if(inch=='.') {isd=true; num=0;} Elsenum=inch-'0'; if(!IsD) {                 while(inch=getchar (),inch>='0'&&inch<='9') {num*=Ten; num+=inch-'0';} }        if(inch!='.'){                if(IsN) num=-num; return true; }Else{                 while(inch=getchar (),inch>='0'&&inch<='9') {num+=dec* (inch-'0');D ec*=0.1; }        }        if(IsN) num=-num; return true;}

ACM Principles _ Input Hang

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.