Advertisement
PikMike

Untitled

Apr 23rd, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <algorithm>
  5. #include <functional>
  6. #include <string>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <iostream>
  12.  
  13. #define forn(i, n) for (int (i) = 0; i < (n); ++i)
  14. #define fore(i, l, r) for (int (i) = (l); i < (r); ++i)
  15. #define forr(i, r, l) for (int (i) = (r - 1); i >= (l); --i)
  16. #define all(a) (a).begin(), (a).end()
  17. #define pb push_back
  18. #define mp make_pair
  19. #define sz(a) int((a).size())
  20. #define x first
  21. #define y second
  22. #define li long long
  23. #define ld long double
  24. #define pt pair<int, int>
  25. #define pll pair<li, li>
  26.  
  27. const int INF = 1e9;
  28. const li INF64 = 2e18;
  29. const int MOD = 1e9 + 7;
  30. const ld EPS = 1e-7;
  31.  
  32. using namespace std;
  33.  
  34. int n;
  35. string s;
  36.  
  37.  
  38. void read(){
  39.     string t;
  40.     while (cin >> t)
  41.         s += t;
  42.     n = sz(s);
  43. }
  44.  
  45.  
  46. map<string, string> var;
  47.  
  48.  
  49. void solve(){
  50.     var = map<string, string>();
  51.     printf("{");
  52.     string cur = "";
  53.     int cnt = 0;
  54.     forn(i, n){
  55.         if (s[i] == '<'){
  56.             int pos = -1;
  57.             fore(j, i, n)
  58.                 if (s[j] == '>'){
  59.                     pos = j;
  60.                     break;
  61.                 }
  62.             string t = s.substr(i + 1, pos - i - 1);
  63.             i = pos;
  64.             if (t == "configuration" || t.substr(1, sz(t) - 1) == "configuration")
  65.                 continue;
  66.             if (t[0] == '/'){
  67.                 var[t.substr(1, sz(t) - 1)] = cur;
  68.                 printf("\"%s\"", cur.c_str());
  69.                 cur = "";
  70.                 cnt++;
  71.                 if (i < sz(s) - 17)
  72.                     printf(",");
  73.             }
  74.             else{
  75.                 printf("\n    \"%s\": ", t.c_str());
  76.             }
  77.         }
  78.         else if (s[i] == '$'){
  79.             int pos = -1;
  80.             fore(j, i + 1, n)
  81.                 if (s[j] == '}'){
  82.                     pos = j;
  83.                     break;
  84.                 }
  85.             string t = s.substr(i + 2, pos - i - 2);
  86.             cur += var[t];
  87.             i = pos;
  88.         }
  89.         else{
  90.             cur += s[i];
  91.         }
  92.     }
  93.     if (cnt)
  94.         printf("\n");
  95.     printf("}\n");
  96. }
  97.  
  98.  
  99. int main(){
  100. #ifdef _DEBUG
  101.     freopen("input.txt", "r", stdin);
  102.     freopen("output.txt", "w", stdout);
  103. #endif
  104.     read();
  105.     solve();
  106.     return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement