栈写法——STL版
2025-07-08 16:04:10
发布于:广东
9阅读
0回复
0点赞
由于手搓函数太麻烦,我给大家提供STL版题解
#include<iostream>
#include<stack>
using namespace std;
stack<char> sbb;
int main(){
string a;
bool b2 = 0;
cin>>a;
int x,rx;
for(int i = 0 ; i < a.size(); i ++){
if(a[i] == '('){
sbb.push(a[i]);
}
else if(a[i] == ')'){
if(!sbb.empty()){
sbb.pop();
}
else{
cout<<"NO";
b2 = 1;
break;
}
}
else{
continue;
}
}
if(b2 == 0){
if(sbb.empty()){
cout<<"YES";
}
else{
cout<<"NO";
}
}
return 0;
}
全部评论 1
假的
5天前 来自 广东
0
有帮助,赞一个