首先,我们需要一个暴力程序(暂名为baoli.cpp),将其放入一个固定的文件夹(此处命名为对拍)
运行,我们可以得到baoli.exe
然后,用我们需要测试的程序(暂名为ceshi.cpp),放入对拍文件夹
运行,得到ceshi.exe
此时,我们写一个生成数据的文件,暂名为makedata.cpp
具体内容(此处模拟生成A+B的数据):
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cstdlib>
using namespace std;
int main(){
freopen("shuju.in","w",stdout);
srand(unsigned(time(NULL)));
int a=rand()%1e9+1;
int b=rand()%1e9+1;
cout<<a<<" "<<b<<endl;
fclose(stdout);
return 0;
}这是makedata.cpp,放入对拍文件夹,运行后同样得到makedata.exe
此时,在对拍文件夹中新建一个txt文件,名字随便,但后缀要修改为.bat(此处暂名为对拍主程序.bat)
写入代码
:loop
makedata.exe
std.exe
baoli.exe
fc std.out baoli.out
if %errorlevel% == 1 pause
goto loop
一切就绪之后,运行对拍主程序.bat,会打开一个界面
若此时显示暂停,即
请按任意键继续……
则要测试的程序不与暴力程序的结果一致
若一直死循环,则要测试的程序与暴力程序的结果一致
注意!源程序和暴力程序中均需要加入freopen!
