对拍

对拍

步骤:

1.先写出自己的代码并运行

2.写出暴力代码并运行

3.写随机数生成器

#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
int main(){
    srand(time(0));
    freopen("in.in", "w", stdout);
    int a = rand(), b = rand();
    printf("%d %d\n", a, b);
}

4.写对拍程序

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
    while(1){
        system("data.exe");
        system("baoli.exe");
        double begin=clock();
        system("std.exe");
        double end=clock();
        printf("运行时间%.4lf",(end-begin)/1000);
        if (system("fc std.txt baoli.txt")) //当 fc 返回1时,说明这时数据不一样
            break;                          //不一样就跳出循环
        cout<<"找不到差异"<<endl<<endl;
    }
    return 0;
}

对拍程序优化: 加入输出运行时间

posted @ 2021-10-21 22:31  RevolutionBP  阅读(71)  评论(0编辑  收藏  举报