Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <complex>
- #include <cstdlib>
- #include <ctime>
- #include <deque>
- #include <iostream>
- #include <map>
- #include <math.h>
- #include <queue>
- #include <random>
- #include <set>
- #include <string>
- #include <stack>
- #include <unordered_map>
- #include <unordered_set>
- #include <vector>
- using namespace std;
- typedef long long ll;
- typedef double ld;
- typedef complex<ld> cp;
- const ld eps = 1e-9;
- std::random_device randD;
- std::mt19937 gen(randD());
- const ld pi = 3.14159265359;
- vector<int> v;
- int pr[100010];
- int suf[100010];
- int s[100010];
- stack<pair<int, string>> st;
- int main() {
- #ifdef SYSTEM
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- string s;
- cin >> s;
- st.push({ 1, "" });
- for (int i = 0; i < s.length(); ++i) {
- if (s[i] == '(') {
- ++i;
- int mult = 0;
- while (i < s.length() && s[i] >= '0' && s[i] <= '9') {
- mult *= 10;
- mult += s[i] - '0';
- ++i;
- }
- st.push({mult, ""});
- --i;
- } else if (s[i] == ')') {
- auto x = st.top();
- st.pop();
- string t = "";
- for (int j = 0; j < x.first; ++j) {
- t += x.second;
- }
- st.top().second += t;
- }
- else {
- st.top().second += s[i];
- }
- }
- cout << st.top().second;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment