跳到正文

算法·理论

对拍

Mason123456约 4 分钟
原文
文章信息与版本

文章信息

收录
2026年2月6日
更新
2026年2月6日
篇幅
约 4 分钟

版本

  1. v4当前
  2. v3
  3. v2
  4. v1

Masonの对拍

朴素考场对拍

C++
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
int main() {
	for (int i = 1;i <= 100;i++) {
		system("gen > test.in.txt");
		system("test1.exe < test.in.txt > a.out.txt");
		system("test2.exe < test.in.txt > b.out.txt");
		std::cout<<i<<"small\n";
		if (system("fc a.out.txt b.out.txt")) {
			system("pause");
			return 0;
		}
	}
}

小数据+大数据对拍

C++
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
int main() {
	for (int i = 1;i <= 100;i++) {
		system("gen1 > test.in.txt");
		system("test1.exe < test.in.txt > a.out.txt");
		system("test2.exe < test.in.txt > b.out.txt");
		std::cout<<i<<"small\n";
		if (system("fc a.out.txt b.out.txt")) {
			system("pause");
			return 0;
		}
	}
	for (int i = 1;i <= 50;i++) {
		system("gen2 > test.in.txt");
		system("test1.exe < test.in.txt > a.out.txt");
		system("test2.exe < test.in.txt > b.out.txt");
		std::cout<<i<<"big\n";
		if (system("fc a.out.txt b.out.txt")) {
			system("pause");
			return 0;
		}
	}
}

BEAUTIFUL の 对拍

C++
#include <bits/stdc++.h>
using namespace std;
void printf_green(const char *s)
{
	printf("\033[0m\033[1;32m%s\033[0m", s);
}

void printf_red(const char *s)
{
    printf("\033[0m\033[1;31m%s\033[0m", s);
}

bool check()
{
	string ans,ans2;
	freopen("a.out.txt","r",stdin);
	char c;
	while(scanf("%c",&c)!=EOF) ans+=c;
	fclose(stdin);
	freopen("b.out.txt","r",stdin);
	while(scanf("%c",&c)!=EOF) ans2+=c;;
	fclose(stdin);
	return ans == ans2;
}
int main() {
	for(int i = 1; i <= 500;i++) {
		system("gen > test.in.txt");
		system("test1.exe < test.in.txt > a.out.txt");
		system("test2.exe < test.in.txt > b.out.txt");

		if (check()) {
			printf_green("AC on test ");
			string a = to_string(i);
			char ch[1000];
			strcpy(ch, a.c_str());
			printf_green(ch);
			cout<<"\n";
		}
		else{
			printf_red("WA on test ");
			string a = to_string(i);
			char ch[1000];
			strcpy(ch, a.c_str());
			printf_red(ch);
			cout<<"\n";
			return 0;
		}
	}
	printf_green("ALL TESTS RIGHT");
}
原文