-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path551.cpp
More file actions
35 lines (33 loc) · 680 Bytes
/
Copy path551.cpp
File metadata and controls
35 lines (33 loc) · 680 Bytes
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
32
33
34
35
#include <iostream>
#include <stack>
using namespace std;
int main(){
string a;
unsigned int i;
while(cin >> a){
stack< pair<string, int> > s;
for(i=0; i<a.size(); i++){
if(a[i]=='('){
if(a[i+1]=='*') s.push(make_pair("(*", i+1));
else s.push(make_pair("(", i+1));
}
else if(a[i]=='[') s.push(make_pair("[", i+1));
else if(a[i]=='{') s.push(make_pair("{", i+1));
else if(a[i]=='<') s.push(make_pair("<", i+1));
else if(a[i]==')'){
if(s.empty()){
printf("NO %d\n", i+1);
break;
}
else if(s.top().first != "("){
printf("NO %d\n", s.top().second);
break;
}
else{
s.pop();
}
}
}
}
return 0;
}