文章
34
粉丝
18
获赞
6
访问
14.5k
#include <iostream>
#include <stack>
using namespace std;
int main(){
string s;
cin >> s;
stack<char> st;
for(int i = 0;i < s.size();i ++){
if(s[i] == '[' || s[i] == '('){
st.push(s[i]);
}else if(s[i] == ')'){
if(st.empty()){
cout << "NO" << endl;
return 0;
}else{
if(st.top() == '('){
st.pop();
}else{
cout << "NO" << endl;
return 0;
}
}
}else if(s[i] == ']'){
if(st.empty()){
cout << "NO" << endl;
return 0;
}else{
if(st.top() == '['){
st.pop();
}else{
cout << "NO" << endl;
return 0;
}
}
}
}
if(st.empty()){
cout << "YES" << endl;
}else {
cout << "NO" << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发