跳到正文

个人记录

解谜数据生成器

MineCraftLittlePea约 6 分钟
原文

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

文章信息与版本

文章信息

发布
2025年11月5日
收录
2025年12月12日
更新
2026年11月8日
篇幅
约 6 分钟

版本

  1. v2当前
  2. v1
C++
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int x,p,m;
int inputIntInRange(int x,int y,string p) {
	int out;
	cout << "输入" << p << ":";
	cin >> out;
	while (out < x || y < out) {
		cout << "范围 " << x << "~" << y << ",重新输入:";
		cin >> out;
	}
	return out;
}
double inputDoubleInRange(double x,double y,string p) {
	double out;
	cout << "输入" << p << ":";
	cin >> out;
	while (out < x || y < out) {
		cout << "范围 " << x << "~" << y << ",重新输入:";
		cin >> out;
	}
	return out;
}
string inputString(string p) {
	string x;
	cout << "输入" << p << ":";
	cin.ignore(); // 重要!!!
	getline(cin,x);
	return x;
}
bool inputYesNo(string p) {
	string out;
	cout << p << ":(yes 或 no)";
	cin >> out;
	while (out != "yes" && out != "no") {
		cout << "只能输入 yes 或 no,重新输入:";
		cin >> out;
	}
	return out == "yes";
}
string inputEnd() {
	if (inputYesNo("得部分分还是直接0%和100%(前者为 yes)")) {
		double point = inputDoubleInRange(0.0,1.0,"当前结束点得分比例");
		string p = inputString("提示信息");
		return "quitp(" + to_string(point) + ",\"" + p + "\");";
	}
	string isok = inputYesNo("AC吗")?"_ok":"_wa";
	string p = inputString("提示信息");
	return "quitf(" + isok + ",\"" + p + "\");";
}
void writeInTestcase() {
	for (int i = 1; i <= x; ++i) {
		string infname = "test-" + to_string(i) + ".in";
		string outfname = "test-" + to_string(i) + ".out";
		freopen(&infname[0],"w",stdout);
		cout << i;
		fclose(stdout);
		freopen(&outfname[0],"w",stdout);
		fclose(stdout);
	}
}
void writeInchecker() {
	string ans =
R"(#include "testlib.h"
int main(int argc, char* argv[]) {
	registerTestlibCmd(argc, argv);
	std::vector<std::string> ns;
)";
	ans += "\tfor(int i = 1; i <= " + to_string(m) + "; ++i) {\n";
	ans +=
R"(		std::string n = ouf.readToken();
		ns.emplace_back(n);
	}
	int x = inf.readInt();
	ouf.eof();
)";
	for (int i = 1; i <= p; ++i) {
		cout << "当前:用户输入情况 " << i << endl;
		ans += "\t";
		if (i == 1) ans += "if (ns == vector<std::string>(";
		else ans += "} else if (ns == vector<std::string>(";
		for (int j = 1; j <= m; ++j) {
			string now = inputString("用户输入内容 " + to_string(j));
			ans += "\"" + now + "\"";
			if (j != m) ans += ",";
		}
		ans += ")) {\n";
		if (inputYesNo("统一输出吗")) {
			cout << "用户输入情况 " << i << ":统一输出\n";
			ans += "\t\t" + inputEnd() + "\n";
		} else {
			cout << "用户输入情况 " << i << ":分别输出\n";
			for (int j = 1; j <= x; ++j) {
				cout << "当前:测试点 " << j << endl;
				ans += "\t\t";
				if (j == 1) ans += "if (x == 1) " + inputEnd() + "\n";
				else ans += "else if (x == " + to_string(j) + ") " + inputEnd() + "\n";
			}
		}
	}
	{
		cout << "当前:else 块\n";
		ans += "\t} else " + inputEnd() + "\n";
	}
	ans += "}";
	freopen("checker.cpp","w",stdout);
	cout << ans;
	fclose(stdout);
}
signed main() {
	x = inputIntInRange(1,9,"测试点个数");
	p = inputIntInRange(1,20,"用户输入判断情况(不包括 else 块)总数");
	m = inputIntInRange(1,3,"用户输入字符串个数");
	writeInTestcase();
	writeInchecker();
    return 0;
}