文章
77
粉丝
1
获赞
295
访问
5.7k
#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(st.empty()){
cout << "NO";
return 0;
}
char t = st.top();
st.pop();
if(s[i]==')' && t!='('){
cout << "NO";
return 0;
}
if(s[i]==']' && t!='['){
cout << "NO";
return 0;
}
}
}
if(st.empty())
cout << "YES";
else
cout << "NO";
return 0;
}
登录后发布评论
暂无评论,来抢沙发