C++对拍模版

发布时间 2023-10-01 18:08:46作者: yhx0322

Windows

check.cpp

#include <bits/stdc++.h>

using namespace std;

int main()
{
	while( true )
	{
		system( "data.exe" );
		system( "std.exe" );
		system( "brute.exe" );
		if( system( "fc std.out brute.out" ) )
		{
			cout << "WA" << endl;
			return 0;
		}
		cout << "AC" << endl;
	}
	return 0;
}

Mac/Linux

#include <bits/stdc++.h>

using namespace std;

int main() {
	for (int i = 1; i <= 1000; i++) {
		if (i == 1) { // 重新编译
			system("g++ -o brute brute.cpp");
			system("g++ -o std std.cpp");
			system("g++ -o data data.cpp");
		}
		system("./data");
		system("./brute");
		double st = clock();
		system("./std");
		double ed = clock();
		if (system("diff brute.out std.out")) {
			printf("WA\n");
			return 0;
		}
		printf("AC #%d Time:%.0lf ms\n", i, ed - st);
	}
	return 0;
}

随机数生成要点

srand(time(0)); //以当前时间为随机种子

rand(); //生成随机数

生成随机数据

#include <bits/stdc++.h>

using namespace std;

double random_num() {
	... //生成随机数据
}

int main()
{
	freopen( "data.in" , "w" , stdout ); //一定记得开w模式!
	srand(time(0));
	cout << random_num() << " " << random_num();
	return 0;
}