文章
17
粉丝
0
获赞
5
访问
1.3k
//解题思路:map映射字符为整数,结合数据结构的stack进行括号匹配。
#include<iostream>
#include<map>
#include<stack>
using namespace std;
map<char,int> Bracket={{'{',-4},{'[',-3},{'(',-2},{'<',-1},{'>',1},{')',2},{']',3},{'}',4}};
bool match(const string &str){
bool flag=true;
stack<char> S;
for(int i=0;i<str.length();i++){
if(S.empty()){
if(Bracket[str[i]]>0){
flag=false;
break;
}
else S.push(str[i]);
}
&n...
登录后发布评论
暂无评论,来抢沙发