Vserosbuybuy

Untitled

Oct 24th, 2020
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <algorithm>
  2. #include <complex>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <deque>
  6. #include <iostream>
  7. #include <map>
  8. #include <math.h>
  9. #include <queue>
  10. #include <random>
  11. #include <set>
  12. #include <string>
  13. #include <stack>
  14. #include <unordered_map>
  15. #include <unordered_set>
  16. #include <vector>
  17.  
  18. using namespace std;
  19.  
  20. typedef long long ll;
  21. typedef double ld;
  22. typedef complex<ld> cp;
  23.  
  24. const ld eps = 1e-9;
  25. std::random_device randD;
  26. std::mt19937 gen(randD());
  27. const ld pi = 3.14159265359;
  28.  
  29. vector<int> v;
  30. int pr[100010];
  31. int suf[100010];
  32. int s[100010];
  33.  
  34. stack<pair<int, string>> st;
  35.  
  36. int main() {
  37. #ifdef SYSTEM
  38.     freopen("input.txt", "r", stdin);
  39.     freopen("output.txt", "w", stdout);
  40. #endif
  41.     ios_base::sync_with_stdio(false);
  42.     cin.tie(0);
  43.     string s;
  44.     cin >> s;
  45.     st.push({ 1, "" });
  46.     for (int i = 0; i < s.length(); ++i) {
  47.         if (s[i] == '(') {
  48.             ++i;
  49.             int mult = 0;
  50.             while (i < s.length() && s[i] >= '0' && s[i] <= '9') {
  51.                 mult *= 10;
  52.                 mult += s[i] - '0';
  53.                 ++i;
  54.             }
  55.             st.push({mult, ""});
  56.             --i;
  57.         } else if (s[i] == ')') {
  58.             auto x = st.top();
  59.             st.pop();
  60.             string t = "";
  61.             for (int j = 0; j < x.first; ++j) {
  62.                 t += x.second;
  63.             }
  64.             st.top().second += t;
  65.         }
  66.         else {
  67.             st.top().second += s[i];
  68.         }
  69.     }
  70.     cout << st.top().second;
  71.     return 0;
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment