版本比较
解谜数据生成器
正文
增加 40 行删除 25 行
2 行未改动34567891011121314151617182 行未改动212223242526272829303132333435363738394041424344458 行未改动545556575859606162636465666768697071727374757677788 行未改动878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201212 行未改动#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;2 行未改动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)")) {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);}}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();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";}}}{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;}```2 行未改动3456789101112131415161718192021222324252 行未改动282930313233343536373839404142434445464748495051525354558 行未改动6465666768697071727374757677787980818283848586878889909192939495969798991001018 行未改动1101111121131141151161171181191201211221231241251261271281291301311321331341351362 行未改动#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 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)")) {8 行未改动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();8 行未改动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 重新定制 checkerx = inputIntInRange(1,9,"测试点个数");p = inputIntInRange(1,20,"用户输入判断情况(不包括 else 块)总数");m = inputIntInRange(1,3,"用户输入字符串个数");writeInTestcase();writeInchecker();system("checker.cpp");return 0;}```