Tip_对拍

bat文件
生成.bat

@echo off 
:loop 
data.exe //生成数据
right.exe  //std
test.exe //测试数据
fc right.out test.out 
if not errorlevel 1 goto loop
pause
goto loop 

C++版详讲对拍
对拍用于验证算法正确性,不保证运行时间!!
一般有四个文件
一个对拍文件 dp.exe/dp.cpp
一个生成数据程序 data.exe/data.cpp
一个标准程序(一般会比较慢,但保证正确) std.exe/std.cpp
一个测试的程序 problem.exe/problem.cpp

下面以A+B问题为例,解释一下对拍代码

生成数据代码

#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<iostream>
using namespace std;
int main(){
    freopen("problem.in","w",stdout);//注意这里是输出,不是读入
    srand(time(0));//根据时间置随机数 这样随机数周期长 近似认为是随机数 最大值为32767
    //如果需要更大的数据可以 
    //rand()*rand()%DARA_MAX; 
    printf("%d %d\n",rand(),rand());
    return 0;
}

标准程序代码//瞎写的qwq;

#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    freopen("problem.in","r",stdin);
    freopen("std.out","w",stdout);
    int a,b;
    cin>>a>>b;
    while(b--) a++;
    cout<<a;
    return 0;
}

验证算法

#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    freopen("problem.in","r",stdin);
    freopen("problem.out","w",stdout);
    int a,b;
    cin>>a>>b;
    cout<<a+b;
    return 0;
} 

核心对拍代码

#include<cstdlib>
#include<iostream>
using namespace std;
int main(){
    do{
        system("data.exe");
        system("std.exe");
        system("problem.exe"); 
    }while(!system("fc std.out problem.out"));
    return 0;
}

所有文件如图所示
这里写图片描述

运行结果如图所示
这里写图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值