Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define newline '\n'
- #define uns unsigned
- #define ll long long
- #define deb(x) clog << x << ' '
- #define debnewL(x) clog << x << newline
- using namespace std;
- ///*********************
- string s;
- uns it, nrp;
- inline void PassSpecChars()
- {
- while(it < s.size() && strchr("[]", s[it]))
- {
- if (s[it] == '[')
- nrp++;
- else
- nrp--;
- it++;
- }
- }
- inline string eval()
- {
- PassSpecChars();
- if (it == s.size() - 1)
- return "";
- int nr = 0;
- while (it < s.size() && isdigit(s[it]))
- {
- nr = nr * 10 + int(s[it] - '0');
- it++;
- }
- PassSpecChars();
- string r = "";
- while (it < s.size() && (isalpha(s[it]) or isdigit(s[it])) && s[it] != ']')///2[a2[b]]
- {
- if (isdigit(s[it]))
- {
- r += eval();
- it++;
- continue;
- }
- r += s[it];
- it++;
- }
- string cr = r;
- while (--nr)
- r += cr;
- if (it < s.size() - 1 && !nrp)
- {
- if (isdigit(s[it]))
- r += eval();
- }
- return r;
- }
- int main()
- {
- getline(cin, s);
- do
- {
- cout << eval();
- it++;
- }
- while (it < s.size());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement