Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <algorithm>
- #include <functional>
- #include <string>
- #include <vector>
- #include <set>
- #include <map>
- #include <queue>
- #include <iostream>
- #define forn(i, n) for (int (i) = 0; i < (n); ++i)
- #define fore(i, l, r) for (int (i) = (l); i < (r); ++i)
- #define forr(i, r, l) for (int (i) = (r - 1); i >= (l); --i)
- #define all(a) (a).begin(), (a).end()
- #define pb push_back
- #define mp make_pair
- #define sz(a) int((a).size())
- #define x first
- #define y second
- #define li long long
- #define ld long double
- #define pt pair<int, int>
- #define pll pair<li, li>
- const int INF = 1e9;
- const li INF64 = 2e18;
- const int MOD = 1e9 + 7;
- const ld EPS = 1e-7;
- using namespace std;
- int n;
- string s;
- void read(){
- string t;
- while (cin >> t)
- s += t;
- n = sz(s);
- }
- map<string, string> var;
- void solve(){
- var = map<string, string>();
- printf("{");
- string cur = "";
- int cnt = 0;
- forn(i, n){
- if (s[i] == '<'){
- int pos = -1;
- fore(j, i, n)
- if (s[j] == '>'){
- pos = j;
- break;
- }
- string t = s.substr(i + 1, pos - i - 1);
- i = pos;
- if (t == "configuration" || t.substr(1, sz(t) - 1) == "configuration")
- continue;
- if (t[0] == '/'){
- var[t.substr(1, sz(t) - 1)] = cur;
- printf("\"%s\"", cur.c_str());
- cur = "";
- cnt++;
- if (i < sz(s) - 17)
- printf(",");
- }
- else{
- printf("\n \"%s\": ", t.c_str());
- }
- }
- else if (s[i] == '$'){
- int pos = -1;
- fore(j, i + 1, n)
- if (s[j] == '}'){
- pos = j;
- break;
- }
- string t = s.substr(i + 2, pos - i - 2);
- cur += var[t];
- i = pos;
- }
- else{
- cur += s[i];
- }
- }
- if (cnt)
- printf("\n");
- printf("}\n");
- }
- int main(){
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- read();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement