Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/STACK:167177216")
- #include <stdio.h>
- #include <stack>
- #include <math.h>
- #include <iostream>
- #include <algorithm>
- #include <string.h>
- #include <string>
- #include <memory.h>
- #include <vector>
- #include <map>
- #include <queue>
- #include <set>
- #include <time.h>
- #include <cassert>
- using namespace std;
- #define mp make_pair
- #define pb push_back
- #define pii pair<int, int>
- #define forn(i, n) for(int i = 0; i < (int)(n); i++)
- #define x first
- #define y second
- typedef long long li;
- typedef long double ld;
- typedef unsigned long long uli;
- const int INF = 1e9;
- const ld eps = 1e-9;
- const li mod = INF + 7;
- const li INF64 = (li)(INF) * (li)(INF);
- const int ddx[] = {-1, 1, 1, -1};
- const int ddy[] = {1, 1, -1, -1};
- const int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
- const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
- const int dx4[] = {-1, 0, 1, 0};
- const int dy4[] = {0, 1, 0, -1};
- const int dxh[] = {-1, -1, -1, 1, 1, 1, 1, -1};
- const int dyh[] = {1, -1, -1, -1, -1, 1, 1, 1};
- const string dirs[] = {"RIGHT", "UP", "LEFT", "DOWN"};
- string s;
- int toint(string s)
- {
- int res = 0, st = 1;
- for(int i = s.length() - 1; i >= 0; i--)
- {
- res += (s[i] - '0') * st;
- st *= 10;
- }
- return res;
- }
- string calc(int l, int r)
- {
- string res;
- res.erase();
- int idx = l;
- while(idx <= r)
- {
- while(idx <= r && s[idx] != '(')
- {
- res += s[idx];
- idx++;
- }
- if(idx > r)
- break;
- idx++;
- string val;
- while(s[idx] >= '0' && s[idx] <= '9')
- {
- val += s[idx];
- idx++;
- }
- int nidx = idx;
- int rr;
- int kol = 1;
- for(int i = idx; i <= r; i++)
- {
- if(s[i] == '(')
- kol++;
- if(s[i] == ')')
- kol--;
- if(kol == 0)
- {
- rr = i;
- break;
- }
- }
- //cout << "rr == " << rr << endl;
- //while(s[idx] != ')')
- //idx++;
- int cnt = toint(val);
- forn(kk, cnt)
- res += calc(nidx, rr - 1);
- idx = rr + 1;
- }
- return res;
- }
- int main()
- {
- //freopen("input.txt","r",stdin);
- //freopen("output.txt","w",stdout);
- ios_base::sync_with_stdio(false);
- getline(cin, s);
- cout << calc(0, s.length() - 1) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment