Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <iostream>#include <bits/stdc++.h>using namespace std;string s;int len;stack<int> st;vector<int> l_ans, r_ans;int tail = 0;int main() {ios::sync_with_stdio(false);cin.tie(0);cin >> s;len = s.length();l_ans.resize(len);r_ans.resize(len);tail = 0;for (int i = 0; i < len; ++i) {if (s[i] == '(') {l_ans[tail] = i;st.push(tail++);} else {int id = st.top();st.pop();r_ans[id] = i;}}for (int i = 0; i < tail; ++i)cout << l_ans[i] + 1 << " " << r_ans[i] + 1 << "\n";return 0;