Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <map>
  5. #include <iomanip>
  6. #include <stack>
  7. #include <string>
  8. #include <set>
  9. #include <queue>
  10. #include <functional>
  11. #include <deque>
  12. #include <cmath>
  13. #include <sstream>
  14. #include <bitset>
  15. #define forn(n,k) for(int i=k;i<n;i++)
  16. #define All(x) x.begin(),x.end()
  17. #define nope string::npos
  18. #define IO_OPTIMAZE ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  19. #define MAXN 1e9
  20. #define int long long
  21. using namespace std;
  22. stack<int> q;
  23. string solve_str(string str) {
  24.     int j = 0;
  25.     while (str[j] - '0' >= 0 && str[j] - '0' <= 9)
  26.         j++;
  27.     int len = stoi(str.substr(0, j));
  28.     string res = "";
  29.     forn(len, 0)
  30.         res += str.substr(j, str.size());
  31.     return res;
  32. }
  33.  
  34. string sub(string str, int l, int r) {
  35.     string res = "";
  36.     forn(r, l)
  37.         res += str[i];
  38.     return res;
  39. }
  40.  
  41. string res_str(string str) {
  42.     forn(str.size(), 0) {
  43.         if (str[i] == '(')
  44.             q.push(i);
  45.         if (str[i] == ')') {
  46.             int l = q.top();
  47.             q.pop();
  48.             string res = sub(str,l+1,i);
  49.             string no = solve_str(res);
  50.             res = no;
  51.             str = str.substr(0, l).append(res.append(str.substr(i+1, str.size())));
  52.             i = no.size()+l-1;
  53.         }
  54.     }
  55.     return str;
  56. }
  57.  
  58. signed main() {
  59. #ifdef dryu
  60.     freopen("input.txt", "r", stdin);
  61. #endif
  62.     IO_OPTIMAZE;
  63.     string str;
  64.     cin >> str;
  65.     cout << res_str(str);
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement