跳到正文

个人记录

对拍

CocoonBroken约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月14日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

同一目录下需要准备如下文件,建议单独建一个文件夹:

  1. data.cpp 构造数据的程序
  2. data.out/date.exe 构造数据的程序生成的可执行文件
  3. a.cpp 待验证程序
  4. a.out/a.exe
  5. tmp_a.out 待验证程序的输出
  6. b.cpp 暴力程序
  7. b.out/b.exe 暴力程序生成的可执行文件
  8. tmp_b.out 暴力程序的输出
  9. check.cpp 对拍程序
  10. check.out/check.exe 对拍程序生成的可执行文件

注意:可根据个人习惯给文件命名。

下面以 A+B problem 为例:

数据生成:

C++
#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;
}

待验证程序:

C++
#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;
}

暴力程序:

C++
#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;
}

对拍程序:

C++
#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;
}
原文