-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbracket_matching.cpp
More file actions
53 lines (50 loc) · 852 Bytes
/
Copy pathbracket_matching.cpp
File metadata and controls
53 lines (50 loc) · 852 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
*Bracket_matching
*2018Äê7ÔÂ11ÈÕ 21:17:35
*/
#include<iostream>
#include<stack>
#include<vector>
bool paren(const std::vector<char> exp){
std::stack<char> s;
for(int i=0;i<exp.size();i++)
{
switch(exp[i])
{
case'(':case'[':case'{':
s.push(exp[i]);
break;
case')':
if(s.empty()||('('!=s.top()))
return false;
else if('('==s.top())
s.pop();
break;
case']':
if(s.empty()||('['!=s.top()))
return false;
else if('['==s.top())
s.pop();
break;
case'}':
if(s.empty()||('{'!=s.top()))
return false;
else if('{'==s.top())
s.pop();
break;
default: break;
}
}
return s.empty();
}
int main(){
// char v[]={'3','(','5','+'};
std::vector<char> v;
char c;
while(std::cin>>c)
v.push_back(c);
if(paren(v))
std::cout<<"match";
else
std::cout<<"No_match";
}