研究性学习代码

输入

scanf

#include<algorithm> 
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

int lin[1000050]; 



int main()
{
        freopen("1.in","r",stdin);
    clock_t start = clock();
    for(int i = 1;i <= 1000000;i ++)
        scanf("%d",&lin[i]);
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;
    
}

gets

#include<algorithm> 
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

char lin[7000000]; 

int main()
{
    freopen("1.in","r",stdin);
    clock_t start = clock();
    gets(lin);
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;
    
}

getline

#include<algorithm> 
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

string lin;

int main()
{
        freopen("1.in","r",stdin);
    clock_t start = clock();
    getline(cin,lin);
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;
}

cin.getline

#include<algorithm> 
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

char lin[7000000]; 

int main()
{
    freopen("1.in","r",stdin);
    clock_t start = clock();
    cin.getline(lin,6888898);
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;
}

cin

#include<algorithm> 
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

int lin[1000050]; 



int main()
{
    freopen("1.in","r",stdin);
    clock_t start = clock();
    for(int i = 1;i <= 1000000;i ++)
        cin >> lin[i]; 
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;

    
}

getchar

#include<algorithm> 
#include<iostream>
#include<cstring>
#include<cstdio>
#include<ctime>
#include<cmath>
using namespace std;

int lin[1000050]; 

inline void re(int &x)
{
    x = 0;
    char a = getchar();bool b = 0;
    while(a < '0' || a > '9')
    {
        if(a == '-')
            b = 1;
        a = getchar();
    }
    while(a >= '0' && a <= '9')
        x = x * 10 + a - '0',a = getchar();
    if(b)
        x *= -1;
}

int main()
{
    freopen("1.in","r",stdin);
    clock_t start = clock();
    for(int i = 1;i <= 1000000;i ++)
        re(lin[i]);
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;

    
}

输出

cout(结果转为字符串)

#include<iostream>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
using namespace std;
int main()
{
        freopen("1.out","w",stdout);
    clock_t start = clock();
    for(int i = 1;i <= 1000000 ;i ++)
    {
        stringstream ss;
        string qwq;
        ss << i;
        ss >> qwq;
        cout << qwq << ' ';
    }
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;
    
} 

 

 cout

#include<algorithm> 
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

int lin[10000010]; 

int main()
{
        freopen("1.out","w",stdout);
    clock_t start = clock();
    for(int i = 1;i <= 1000000;i ++)
        cout << i << ' '; 
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;
    
}

printf(结果转为字符串)

#include<iostream>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
using namespace std;
int main()
{
        freopen("1.out","w",stdout);
    clock_t start = clock();
    for(int i = 1;i <= 1000000 ;i ++)
    {
        stringstream ss;
        string qwq;
        ss << i;
        ss >> qwq;
        printf("%s ",qwq.c_str());
    }
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;
    
} 

printf

#include<algorithm> 
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

int lin[10000010]; 

inline void re(int &x)
{
    x = 0;
    char a = getchar();bool b = 0;
    while(a < '0' || a > '9')
    {
        if(a == '-')
            b = 1;
        a = getchar();
    }
    while(a >= '0' && a <= '9')
        x = x * 10 + a - '0',a = getchar();
    if(b)
        x *= -1;
}

int main()
{
        freopen("1.out","w",stdout);
    clock_t start = clock();
        for(int i = 1;i <= 1000000;i ++)
        printf("%d ",i);
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;

}

puts

#include<iostream>
#include<cstring>
#include<sstream>
#include<cstdio> 
#include<ctime>
using namespace std;
int main()
{
        freopen("1.out","w",stdout);
    clock_t start = clock();
    for(int i = 1;i <= 1000000 ;i ++)
    {
        char qwq[10];
        sprintf(qwq,"%d",i);
        puts(qwq);
    }
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;
    
} 

putchar

#include<algorithm> 
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<ctime> 
using namespace std;

int lin[10000010]; 

inline void write(int x)
{
    if(x<0)
        putchar('-'),x*=-1;
    if(x/10)
        write(x/10);
    putchar(x%10+'0');
}

int main()
{
        freopen("1.out","w",stdout);
    clock_t start = clock();
    for(int i = 1;i <= 1000000;i ++)
        write(i),putchar(' ');
    clock_t ends = clock(); 
    cout <<"Running Time : "<<(double)(ends - start)/ CLOCKS_PER_SEC << 's' << endl;
    
}

 

posted @ 2018-01-28 11:44  那一抹落日的橙  阅读(269)  评论(1编辑  收藏  举报