题解
2023-07-06 13:42:46
发布于:上海
299阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
char st[1005],TOP=0;
void push(char x){
TOP++;
st[TOP]=x;
}
void pop(){
--TOP;
}
char top(){
return st[TOP];
}
bool empty(){
return TOP==0;
}
void clear(){
TOP=0;
}
int main(){
string a;
cin>>a;
for(int i=0;i<a.length();i++){
if(a[i]=='(')
push(a[i]);
if(a[i]==')'){
if(!empty())
pop();
else{
cout<<"NO";
return 0;
}
}
}
if(empty())
cout<<"YES";
else
cout<<"NO";
return 0;
}
这里空空如也
有帮助,赞一个