Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <iomanip>
- #include <stack>
- #include <string>
- #include <set>
- #include <queue>
- #include <functional>
- #include <deque>
- #include <cmath>
- #include <sstream>
- #include <bitset>
- #define forn(n,k) for(int i=k;i<n;i++)
- #define All(x) x.begin(),x.end()
- #define nope string::npos
- #define IO_OPTIMAZE ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
- #define MAXN 1e9
- #define int long long
- using namespace std;
- stack<int> q;
- string solve_str(string str) {
- int j = 0;
- while (str[j] - '0' >= 0 && str[j] - '0' <= 9)
- j++;
- int len = stoi(str.substr(0, j));
- string res = "";
- forn(len, 0)
- res += str.substr(j, str.size());
- return res;
- }
- string sub(string str, int l, int r) {
- string res = "";
- forn(r, l)
- res += str[i];
- return res;
- }
- string res_str(string str) {
- forn(str.size(), 0) {
- if (str[i] == '(')
- q.push(i);
- if (str[i] == ')') {
- int l = q.top();
- q.pop();
- string res = sub(str,l+1,i);
- string no = solve_str(res);
- res = no;
- str = str.substr(0, l).append(res.append(str.substr(i+1, str.size())));
- i = no.size()+l-1;
- }
- }
- return str;
- }
- signed main() {
- #ifdef dryu
- freopen("input.txt", "r", stdin);
- #endif
- IO_OPTIMAZE;
- string str;
- cin >> str;
- cout << res_str(str);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement