用STACK就不用自己写函数
2025-02-10 20:03:31
发布于:上海
11阅读
0回复
0点赞
#include<iostream>
using namespace std;
int top;
char s[1027];
void push(char x){
s[++top]=x;
}
void pop(){
--top;
}
char Top(){
return s[top];
}
bool empty(){
return top==0;
}
int size(){
return top;
}
int main(){
string a;
cin>>a;
for(int i=0;i<a.size();i++){
if(a[i]=='(')push('(');
else if(a[i]==')'){
if(empty()){
cout<<"NO";
return 0;
}else
pop();
}
}
if(size()==0){
cout<<"YES";
}else cout<<"NO";
return 0;
}
这里空空如也
有帮助,赞一个