hiho week 228 register

Ended

Participants:231

Verdict:Accepted
Score:100 / 100
Submitted:2018-11-13 23:37:15

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
#include "iostream"
#include "algorithm"
#include <stack>
using namespace std;
struct node{
   int l,r;
}ans[1000007];
int cmp(node p,node q){
   return p.l < q.l;
}
int main(){
    string s;
    cin >> s;
    stack<int> st;
    int in =0 ;
    for(int i = 0;i < s.size();++i){
        if( s[i] == '(' ) st.push(i);
        else {
           ans[in].l = st.top();
           st.pop();
           ans[in].r = i;
           in++;
        }
    }
    sort(ans,ans+in,cmp);
    for(int i = 0;i < in;++i) {
        cout << (ans[i].l + 1) <<" " << (ans[i].r + 1) <<endl;
    }
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX