题解
2025-06-22 15:32:15
发布于:浙江
3阅读
0回复
0点赞
#include<iostream>
#include<string>
using namespace std;
char s[30];
int TOP;
string shabby;
void push(char x){
s[++TOP] = x;
}
void pop(){
--TOP;
}
char top(){
return s[TOP];
}
int size(){
return TOP;
}
bool empty(){
return TOP==0;
}
int main(){
cin >> shabby;
for(int i=0;i<shabby.size();i++){
if(shabby[i]=='(')push(s[i]);
if(shabby[i]==')'){
if(empty()){
cout << "NO";
return 0;
}else pop();
}
if(shabby[i]=='@')break;
}
empty() ? cout << "YES" : cout << "NO";
}
全部评论 1
栈的五个函数
void push(char x){ s[++TOP] = x; } void pop(){ --TOP; } char top(){ return s[TOP]; } int size(){ return TOP; } bool empty(){ return TOP==0; }
2025-06-22 来自 浙江
0
有帮助,赞一个