fork download
  1. // Nguyen Thien Nhan (tomato)
  2. #include <bits/stdc++.h>
  3. //#pragma GCC optimize("O3,unroll-loops")
  4. //#pragma GCC target("avx2,bmi,bmi2,popcnt")
  5.  
  6. using namespace std;
  7.  
  8. #define TASK "A"
  9. #define ll long long
  10. #define fi first
  11. #define se second
  12. #define BIT(x, i) (((x) >> (i)) & (1LL))
  13. #define MASK(i) ((1LL) << (i))
  14. #define ii pair<int, int>
  15.  
  16. template<class T> bool maximize(T &a, const T &b) {
  17. return a < b ? a = b, 1 : 0;
  18. }
  19.  
  20. template<class T> bool minimize(T &a, const T &b) {
  21. return a > b ? a = b, 1 : 0;
  22. }
  23.  
  24. const int MAXN = 1e5 + 5;
  25. const int MAXM = 2e5 + 5;
  26. const int MOD = 1e9 + 7;
  27. const int INF = 1e9;
  28.  
  29.  
  30. //---------Variable---------//
  31.  
  32. int numArr;
  33. string s;
  34. stack<pair<int, char>> st;
  35.  
  36. //--------------------------//
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. signed main() {
  45.  
  46. ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  47. // freopen(TASK".INP", "r", stdin);
  48. // freopen(TASK".OUT", "w", stdout);
  49.  
  50. cin >> s;
  51. numArr = s.size();
  52. s = " " + s;
  53. for (int i = 1; i <= numArr; ++i) {
  54. if (st.size() == 0 || s[i] == '(') st.push({i, s[i]});
  55. else {
  56. cout << st.top().fi - 1 << " ";
  57. st.pop();
  58. }
  59. }
  60.  
  61.  
  62. return 0;
  63.  
  64. }
  65.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty