【对拍.bat】里的内容:
@echo off
:loop
rand>in.txt
my<in.txt>myout.txt
std<in.txt>stdout.txt
fc myout.txt stdout.txt
if not errorlevel 1 goto loop
pause
goto loop【rand.cpp】里的内容:
#include<bits/stdc++.h>
using namespace std;
int main(){
srand(time(NULL));
cout<<1<<endl;
for(int t=1;t<=1;++t){
int n=rand()%(10-5+1)+5;
int m=rand()%(50-10+1)+10;
int k=rand()%(7-3+1)+3;
cout<<n<<" "<<m<<" "<<k<<endl;
for(int i=0;i<n;++i){
cout<<rand()%(20-5+1)+5<<" ";
}
cout<<endl;
}
}my.cpp是自己的代码,std.cpp是标准代码。打开【对拍.bat】开始对拍。当对拍结果不一样时,打开myout.txt,会自动停在结果不一致的那组数据。
注意1:有些电脑对拍起来可能超级慢。
注意2:文件夹内的其他.exe文件可能必须删掉。
本文介绍了一个用于比较两个程序输出是否一致的对拍工具。通过批处理脚本和C++程序生成随机测试用例,该工具能够高效地检测两者的输出差异。
1188

被折叠的 条评论
为什么被折叠?



