跳到正文

个人记录

【模板】对拍

myster1ous约 3 分钟
原文

这是 2025年12月25日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年7月29日
收录
2025年12月25日
更新
2026年11月11日
篇幅
约 3 分钟

版本

  1. v2当前
  2. v1
C++
#include <bits/stdc++.h>
#define int long long

signed main() {
//	std::system("g++ {file}.cpp -o {file} -O2 -static -std=c++14");
//	std::system("g++ {file}-gen.cpp -o {file}-gen -O2 -static -std=c++14");
//	std::system("g++ {file}-sol.cpp -o {file}-sol -O2 -static -std=c++14");
	
//	std::cerr << "Successfully compiled three cpp.\n";
	
	int tc = 0;
	while (true) {
		tc += 1;
		std::system("{file}-gen.exe > {file}.in");
		std::system("{file}-sol.exe < {file}.in > {file}.ans");
		
		int tfrom = clock();
		std::system("{file}.exe < {file}.in > {file}.out");
//		int x = std::system("fc P11833.out P11833.ans");
		int tto = clock();

		bool flag = false;
		std::ifstream outin("{file}.out");
		std::ifstream ansin("{file}.ans");
		
		std::string out, ans;
		while (true) {
			bool bln = false;
			bln |= bool(std::getline(outin, out));
			bln |= bool(std::getline(ansin, ans));
			if (!bln) {
				break;
			} else {
				while (out.back() == ' ') out.pop_back();
				while (ans.back() == ' ') ans.pop_back();
				if (out != ans) {
					flag = true;
					break;
				}
			}
		} 
		
		if (flag == 0) {
			std::cerr << "\033[32mAccepted #" << tc << " " << (tto - tfrom) * 1.0 / CLOCKS_PER_SEC << "s " << "\033[0m\n";
		} else {
			std::cerr << "\033[31mUnaccepted #" << tc << "\033[0m\n";
			return 0; 
		}
	}
	
	return 0;
}