T21186题解
  • 板块学术版
  • 楼主zzhpdyx
  • 当前回复3
  • 已保存回复3
  • 发布时间2025/2/6 16:04
  • 上次更新2025/2/6 16:08:30
查看原帖
T21186题解
1456667
zzhpdyx楼主2025/2/6 16:04
#include<bits/stdc++.h>
#include<stack>
using namespace std;
stack<char> st;
string a;
int main(){
int i;
cin>>a;
for(i=0;i<a.size();i++){
if(a[i]=='('||a[i]=='['||a[i]=='{'){
st.push(a[i]);
}
else if(a[i]==')'){
if(st.empty()){
cout<<"NO";
return 0;
}
else{
if(st.top()!='('){
cout<<"NO";
return 0;
}
else st.pop();
}
}
else if(a[i]==']'){
if(st.empty()){
cout<<"NO";
return 0;
}
else{
if(st.top()!='['){
cout<<"NO";
return 0;
}
else st.pop();
}
}
else if(a[i]=='}'){
if(st.empty()){
cout<<"NO";
return 0;
}
else{
if(st.top()!='{'){
cout<<"NO";
return 0;
}
else st.pop();
}
}
}
if(st.empty()) cout<<"YES";
else cout<<"NO";
return 0;
}
2025/2/6 16:04
加载中...