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