Differences in scanf and CIN

Source: Internet
Author: User

Differences in scanf and CIN

Cited example: http://www.cnblogs.com/shenben/p/5516996.html

As you know, there are two types of inputs and outputs in C + +,-scanf and CIN, but there are differences between them, you know? Let's see the assessment below! Test questions:Enter n number, output n number. test Environment:
ubuntu12.04 i3cpu 4G memory 7200 RPM HDD Test Results:Test results using the time test of Linux, the results are as follows: When 10000 sets of data: Real represents the total execution time of the program, user input data on behalf of the users time, SYS represents the system time from the above test results, Seemingly did not find the scanf of the fierce and even seems to be slower (data volatility), then we continue to look down: 100000 sets of data: Then scanf has begun to emerge, but the difference is not very big, we continue to look down! 1000000 sets of data: At this time, we can find that Cin spent more than twice times the scanf!! The following will not continue to test, to this interested or want to verify their own children's shoes can continue .... However, it is said that scanf's input speed is 3 times times more than CIN!! Test summary: From the above test results, you can find the huge difference between scanf and cin! So, what is the main application of this thing? Needless to say, it is the ACM platform! Those algorithms have no problem time overrun children's shoes, you may be because of the use of CIN caused it! The big data range is going to be
#include <cstdio>#include<iostream>using namespacestd;#definell Long Long//Custom Data rangeinline ll read () {register ll F=1, x=0; RegisterCharCh=GetChar ();  while(ch>'9'|| ch<'0'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intMain () {ll n=read (); printf ("%lld\n", N); return 0;}

Faster I have not learned ...

Differences in scanf and CIN

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.