wym1111

Untitled

Dec 8th, 2024
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.02 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int add (string &data, string &tar, int i) {
  5.     while (data[i] != ':') i ++;
  6.     while (data[i] != '"') i ++;
  7.     i ++;
  8.     while (data[i] != '"') {
  9.         if (data[i] == '\\' && data[i + 1] == 'n') {
  10.             tar += '\n';
  11.             i += 2;
  12.             continue;
  13.         }
  14.         if (data[i] == '<') {
  15.             if (data.substr(i, 5) == "<div>") {
  16.                 i += 5;
  17.                 continue;
  18.             }
  19.             if (data.substr(i, 6) == "</div>") {
  20.                 i += 6;
  21.                 continue;
  22.             }
  23.             if (data.substr(i, 4) == "<br>") {
  24.                 tar += '\n';
  25.                 i += 4;
  26.                 continue;
  27.             }
  28.         }
  29.         tar += data[i];
  30.         i ++;
  31.     }
  32.     return ++ i;
  33. }
  34.  
  35. void solve (int id) {
  36.     char filename[30];
  37.     sprintf_s(filename, ".\\%d\\config.json", id);
  38.     ifstream infile;
  39.     infile.open(filename);
  40.    
  41.     char ch;
  42.     string file;
  43.     while (infile.get(ch)) {
  44.         file += ch;
  45.     }
  46.     infile.close();
  47.    
  48.     string title;
  49.     string timelimit;
  50.     string level;
  51.     string description;
  52.     string inputdescription;
  53.     string outputdescription;
  54.     string inputsample;
  55.     string outputsample;
  56.     string hint;
  57.     string source;
  58.    
  59.     for (int i = 0; i < file.size(); i ++) {
  60.         if (file.substr(i, 5) == "title") i = add(file, title, i);
  61.         if (file.substr(i, 9) == "timelimit") i = add(file, timelimit, i);
  62.         if (file.substr(i, 5) == "level") i = add(file, level, i);
  63.         if (file.substr(i, 11) == "description") i = add(file, description, i);
  64.         if (file.substr(i, 15) == "inputdescription") i = add(file, inputdescription, i);
  65.         if (file.substr(i, 16) == "outputdescription") i = add(file, outputdescription, i);
  66.         if (file.substr(i, 11) == "inputsample") i = add(file, inputsample, i);
  67.         if (file.substr(i, 12) == "outputsample") i = add(file, outputsample, i);
  68.         if (file.substr(i, 4) == "hint") i = add(file, hint, i);
  69.         if (file.substr(i, 6) == "source") i = add(file, source, i);
  70.     }
  71.    
  72.     cout << file << endl;
  73.     cout << "[title]\n" << title << "\n\n";
  74.     cout << "[timelimit]\n" << timelimit << "\n\n";
  75.     cout << "[level]\n" << level << "\n\n";
  76.     cout << "[description]\n" << description << "\n\n";
  77.     cout << "[inputdescription]\n" << inputdescription << "\n\n";
  78.     cout << "[outputdescription]\n" << outputdescription << "\n\n";
  79.     cout << "[inputsample]\n" << inputsample << "\n\n";
  80.     cout << "[outputsample]\n" << outputsample << "\n\n";
  81.     cout << "[hint]\n" << hint << "\n\n";
  82.     cout << "[source]\n" << source << "\n\n";
  83.    
  84.     ofstream outfile;
  85.     sprintf_s(filename, "%d.txt", id);
  86.     outfile.open(filename);
  87.     outfile << "[title]\n" << title << "\n\n";
  88.     outfile << "[timelimit]\n" << timelimit << "\n\n";
  89.     outfile << "[level]\n" << level << "\n\n";
  90.     outfile << "[description]\n" << description << "\n\n";
  91.     outfile << "[inputdescription]\n" << inputdescription << "\n\n";
  92.     outfile << "[outputdescription]\n" << outputdescription << "\n\n";
  93.     outfile << "[inputsample]\n" << inputsample << "\n\n";
  94.     outfile << "[outputsample]\n" << outputsample << "\n\n";
  95.     outfile << "[hint]\n" << hint << "\n\n";
  96.     outfile << "[source]\n" << source << "\n\n";
  97.     outfile.close();
  98. }
  99.  
  100. int main () {
  101.    
  102.     for (int i = 1485; i <= 1489; i ++) {
  103.         solve(i);
  104.     }
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment