版本比较
解谜数据生成器
正文
增加 40 行删除 25 行
2 行未改动3456789101112131415161718192021222324252 行未改动282930313233343528363738313239404142434445464748495051525354558 行未改动6465666758596061626869707172737475767778798081828384858687888990919293949596749798991001018 行未改动1101111121139192939495969798991001011021141151161171061181191201211221091101111231241251261271281291301311321331341351362 行未改动#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;2 行未改动 while (out < x || y < out) { cout << "范围 " << x << "~" << y << ",重新输入:"; cin >> out; } userInput += to_string(out) + "\n"; return out;}string inputString(string p) { string x; string out; cout << "输入" << p << ":"; cin.ignore(); // 重要!!! getline(cin,x); return x; 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)")) {8 行未改动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); 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.readToken();R"( std::string n = ouf.readLine(); ns.emplace_back(n); } int x = inf.readInt(); ouf.eof();8 行未改动 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"; } } ans += chooseTestcaseType("用户输入情况 " + to_string(i)); } { cout << "当前:else 块\n"; ans += "\t} else " + inputEnd() + "\n"; ans += "\t} else {\n"; ans += chooseTestcaseType("else 块"); ans += "\t}\n"; } ans += "}"; freopen("checker.cpp","w",stdout); cout << ans; fclose(stdout); 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;}```