研究性学习代码

Posted 那一抹落日的橙

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了研究性学习代码相关的知识,希望对你有一定的参考价值。

输入

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

 

以上是关于研究性学习代码的主要内容,如果未能解决你的问题,请参考以下文章

python 机器学习有用的代码片段

学习笔记:python3,代码片段(2017)

学习 PyQt5。在我的代码片段中找不到错误 [关闭]

PHP必用代码片段

react 对循环warning提示增加key的研究

如何正确地将多个片段添加到片段过渡?