ubuntu和windows下的程序对拍

对拍是一个很重要的技巧,无论是在比赛中还是平时的做题中,对拍往往能轻易发现自己的错误所在或验证自己算法的真实性

首先我们需要两个程序,一个确定的暴力程序,还有一个是你的不确定的“标程”

然后我们需要一个数据生成器,会用rand函数一般就很容易写出来,用ran.in输出即可

最后我们需要一个程序来验证两个程序给出的结果相不相同,下面给出我的代码方便大家参考(方便我蒯

#include<bits/stdc++.h>
using namespace std;
int ca;
int main()
{
	do
	{
		if(ca)
			cout<<ca<<" AC"<<endl;
		system("./ran");
		system("./a");
		system("./b");
		ca++;
	}while(!system("diff 1.out 2.out"));
	cout<<ca<<" WA";
	return 0;
}

这样对拍能给出可以hack掉你的数据和你的错误输出,方便调试,对拍大法好!

add:

windows下的对拍

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int Case=0;
	do
	{
		system("make.exe");
		system("1.exe");
		system("2.exe");
		Case++;
		cout<<Case<<":"<<"AC\n";
	}
	while(!system("fc 1.out 2.out"));
	cout<<"WA";
	return 0;
}

posted @ 2020-01-14 21:32  dz_ice  阅读(144)  评论(0编辑  收藏  举报