文章
61
粉丝
137
获赞
18
访问
40.0k
#include<bits/stdc++.h>
using namespace std;
map<char, char> bkmatch = {{')', '('}, {']', '['}};
bool match(string s);
int main(){
string s;
cin >> s;
if(match(s))
cout << "YES";
else
cout << "NO";
return 0;
}
bool match(string s){
stack<char> stk;
int slen = s.size();
for(int i = 0; i < slen; i++){
if(s[i] == '(' || s[i] == '['){ //左括弧,入栈
stk.push(s[i]);
}else if(s[i] == ')' || s[i] == ']'){ //右括弧,出栈
if(stk.empty()) return false; //栈空无左括号可出
&...
登录后发布评论
暂无评论,来抢沙发