同一目录下需要准备如下文件,建议单独建一个文件夹:
- data.cpp 构造数据的程序
- data.out/date.exe 构造数据的程序生成的可执行文件
- a.cpp 待验证程序
- a.out/a.exe
- tmp_a.out 待验证程序的输出
- b.cpp 暴力程序
- b.out/b.exe 暴力程序生成的可执行文件
- tmp_b.out 暴力程序的输出
- check.cpp 对拍程序
- check.out/check.exe 对拍程序生成的可执行文件
注意:可根据个人习惯给文件命名。
下面以 A+B problem 为例:
数据生成:
#include<bits/stdc++.h>
using namespace std;
int main(){
srand(time(0));
int x=rand();
int y=rand();
printf("%d %d",x,y);
return 0;
}待验证程序:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll x,y;
scanf("%lld %lld",&x,&y);
printf("%lld\n",x*y);
return 0;
}暴力程序:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll x,y;
scanf("%lld%lld",&x,&y);
ll s=0;
for (int i=1;i<=x;++i)s+=y;
printf("%lld",s);
return 0;
}对拍程序:
#include<bits/stdc++.h>
using namespace std;
int main(){
while (true){
system("data.exe > tmp.in");//输入构造数据到tmp.in
system("a.exe < tmp.in > tmp_a.out");//程序a读入tmp.in,输出到tmp_a.out
system("b.exe < tmp.in > tmp_b.out");//程序b读入tmp.in,输出到tmp_b.out
if (system("fc tmp_a.out tmp_b.out")){
printf("WA");
break;//两个输出不同,输出对应的debug信息。结束循环
}else printf("AC");//相同,继续
}
return 0;
}