题解
2024-12-23 21:04:10
发布于:广东
0阅读
0回复
0点赞
#include <iostream>
using namespace std;
char stack[1010];
int top=0;
void push(char x){stack[++top]=x;}
void pop(){top--;}
int size(){return top-0;}
int getTop(){return stack[top];}
bool empty(){return top==0;}
string str;
int main(){
cin>>str;
int n=str.size();
for(int i=0;i<n;i++){
if(str[i]=='(' )push(str[i]);
else if(str[i]==')'){
if(!empty()){
pop();
}
else{
cout<<"NO";
return 0;
}
}
}
if(!empty()) cout<<"NO";
else cout<<"YES";
return 0;
}
这里空空如也
有帮助,赞一个