differences in scanf and CINAs you know, there are two types of inputs, outputs,-SCANF and CIN in C + +, but there are differences between them, you know. Let's take a look at the assessment below.
Test questions:Enter n number, output n number.
test Environment:
ubuntu12.04 i3cpu 4G memory 7200 RPM HDD
Test Code:(in order to test the correctness of the results, keep the other parts (except the input and output)
scanf's code:
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX 1000001
int main (int argc, char const *argv[])
{
freopen ("scan.in", "R", stdin);
int n;
scanf ("%d", &n);
for (int i=0; i<n; i++) {
Scnaf ("%d", A[i]);
}
for (int i=0; i<n; i++) {
printf ("%d", A[i]);
}
return 0;
}
the code for CIN:
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX 1000001
int main (int argc, char const *argv[])
{
freopen ("scan.in", "R", stdin);
int n;
scanf ("%d", &n);
for (int i=0; i<n; i++) {
Scnaf ("%d", A[i]);
}
for (int i=0; i<n; i++) {
printf ("%d", A[i]);
}
return 0;
}
Test Results:The test results use the time test times of Linux and the results are as follows:
10000 sets of data: real represents the total time of the program execution, user input data on behalf of the 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 slow (data volatility), then we look down:
100000 sets of data:
At this time scanf has begun to emerge, but the difference is not very big, let's look down!
1000000 sets of data:
At this point, we can see that CIN used twice times more time than 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 more than 3 times times that of 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 are the ones that have no problem with the time limit of children's shoes, you might be because of the use of CIN caused by it.