hiho week 228 register

Ended

Participants:231

Verdict:Accepted
Score:100 / 100
Submitted:2018-11-11 23:53:09

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX