Advertisement
Guest User

Untitled

a guest
Jan 25th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string code_path[5] = {"sub_1.txt", "sub_2.txt", "sub_3.txt", "sub_4.txt", "sub_5.txt"};
  7. string output_path = "output.cpp";
  8.  
  9. int main()
  10. {
  11.     fstream fin, fout;
  12.     string t, out;
  13.     size_t len, pos;
  14.  
  15.     fout.open(output_path.c_str(), ios::out);
  16.     fout << "#include \"lib1269.h\"\n\n";
  17.  
  18.     for (int i = 0; i < 5; i++) {
  19.         out = "";
  20.         len = 0;
  21.         fin.open(code_path[i].c_str(), ios::in);
  22.         while (getline(fin, t)) {
  23.             len += t.size() + 1;
  24.  
  25.             pos = 0;
  26.             while ((pos = t.find('\\', pos)) != string::npos) t.insert(pos, 1, '\\'), pos += 2;
  27.             pos = 0;
  28.             while ((pos = t.find('\'', pos)) != string::npos) t.insert(pos, 1, '\\'), pos += 2;
  29.             pos = 0;
  30.             while ((pos = t.find('\"', pos)) != string::npos) t.insert(pos, 1, '\\'), pos += 2;
  31.  
  32.             out += t + "\\n";
  33.         }
  34.         fout << "char sol" << i + 1 << '[' << len + 2 << "] = \"" << out << "\";\n";
  35.         fin.close();
  36.     }
  37.     fout << "\nchar* GetCode(int subtask)\n{\n    switch (subtask) {\n        case 1: return sol1;\n"
  38.             "        case 2: return sol2;\n        case 3: return sol3;\n        case 4: return sol4;\n"
  39.             "        case 5: return sol5;\n    }\n    return 0;\n}\n";
  40.     fout.close();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement