码迷,mamicode.com
首页 > 其他好文 > 详细

研究性学习代码

时间:2018-01-28 12:40:23      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:etl   name   bool   gpo   void   print   getchar   tchar   algorithm   

输入

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;
    
}

 

研究性学习代码

标签:etl   name   bool   gpo   void   print   getchar   tchar   algorithm   

原文地址:https://www.cnblogs.com/Loi-dfkdsmbd/p/8370802.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!