解谜数据生成器
MineCraftLittlePea
·
·
个人记录
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int x,p,m;
string userInput = "";
void writeInFile(string fname,string txt) {
ofstream f(fname);
f << txt;
f.close();
}
int inputIntInRange(int x,int y,string p) {
int out;
cout << "输入" << p << ":";
cin >> out;
while (out < x || y < out) {
cout << "范围 " << x << "~" << y << ",重新输入:";
cin >> out;
}
userInput += to_string(out) + "\n";
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;
}
userInput += to_string(out) + "\n";
return out;
}
string inputString(string p) {
string out;
cout << "输入" << p << ":";
cin.ignore(); // 重要!!!
getline(cin,out);
userInput += out + "\n";
return out;
}
bool inputYesNo(string p) {
string out;
cout << p << ":(yes 或 no)";
cin >> out;
while (out != "yes" && out != "no") {
cout << "只能输入 yes 或 no,重新输入:";
cin >> out;
}
userInput += out + "\n";
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";
writeInFile(infname,to_string(i));
writeInFile(outfname,"");
}
}
string chooseTestcaseType(string blockname) {
string out = "";
if (inputYesNo("统一输出吗")) {
cout << blockname << ":统一输出\n";
out += "\t\t" + inputEnd() + "\n";
} else {
cout << blockname << ":分别输出\n";
for (int j = 1; j <= x; ++j) {
cout << "当前:测试点 " << j << endl;
out += "\t\t";
if (j == 1) out += "if (x == 1) " + inputEnd() + "\n";
else out += "else if (x == " + to_string(j) + ") " + inputEnd() + "\n";
}
}
return out;
}
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.readLine();
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";
ans += chooseTestcaseType("用户输入情况 " + to_string(i));
}
{
cout << "当前:else 块\n";
ans += "\t} else {\n";
ans += chooseTestcaseType("else 块");
ans += "\t}\n";
}
ans += "}";
writeInFile("checker.cpp",ans);
writeInFile("userinput.txt",userInput);
}
signed main() {
// freopen("userinput.txt","r",stdin); // 取消注释可以使用之前的 userinput.txt 重新定制 checker
x = inputIntInRange(1,9,"测试点个数");
p = inputIntInRange(1,20,"用户输入判断情况(不包括 else 块)总数");
m = inputIntInRange(1,3,"用户输入字符串个数");
writeInTestcase();
writeInchecker();
system("checker.cpp");
return 0;
}