构造测试数据 + 对比测试数据

ac.cpp

//正确代码
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int Max_n=1e6+10;

int main(){
    int n=100;
    int a,b;
    while(n--){
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}


/**
* Copyright(c)
* All rights reserved.
* Author : Max_n
* Date : 2019-10-04-15.03.21
* Description : 正确代码
*/

wa.cpp

//错误代码
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int Max_n=1e6+10;

int main(){
    int a,b,n=100;
    while(n--){
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}


/**
* Copyright(c)
* All rights reserved.
* Author : Max_n
* Date : 2019-10-04-15.03.29
* Description : 错误代码
*/

data.cpp

//生成随机数据
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int Max_n=1e6+10;

int main(){
    srand(time(0));//time(0):随机种子
    int a,b; int n=100;
    while(n--){
        a=rand()%100+1;
        b=rand()%100+1;
        cout<<a<<" "<<b<<endl;
    }
    return 0;
}


/**
* Copyright(c)
* All rights reserved.
* Author : Max_n
* Date : 2019-10-04-15.03.50
* Description : 生成随机数据
*/

对拍.cpp

//对比测试数据(小数据)
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int Max_n=1e6+10;

int main(){
    int n=100;
    while(n--){
        system("data.exe>data.in");//data.exe 生成 data.in 的数数据 输入写入文件
        system("ac.exe<data.in>ac.out");//ac.exe 读取 data.in 生成 ac.out
        system("wa.exe<data.in>wa.out");
        if(system("fc ac.out wa.out")) break;//system("pause");//比较两个输出结果是否一致
        //Linux 文件比较命令是diff
    }
    return 0;
}


/**
* Copyright(c)
* All rights reserved.
* Author : Max_n
* Date : 2019-10-04-15.10.21
* Description : 对拍
*/

test.cpp

//结果写入文件(提交去掉 #define test即可)
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int Max_n=1e6+10;

int main(){
    #define test
    #ifdef test
        freopen("test.in","r",stdin);
        freopen("test.out","w",stdout);
    #endif // mytest
    int a,b,n=2;
    while(n--){
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}


/**
* Copyright(c)
* All rights reserved.
* Author : Max_n
* Date : 2019-10-04-15.03.21
* Description : 将结果写入文件
*/

运行时间

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
    clock_t startTime=clock();
    for(int i=0;i<1000000;i++){
         i++;
     }
    clock_t endTime=clock();
    cout<<(double)(endTime-startTime)/CLOCKS_PER_SEC<<"s"<<endl;
    return 0;
}
发布了166 篇原创文章 · 获赞 68 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_42217376/article/details/102075098