传统派~栈写法
2024-05-26 11:16:37
发布于:广东
30阅读
0回复
0点赞
栈写法
#include<bits/stdc++.h>
using namespace std;
char s[22];
int TOP=0;
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 (a[i]);
}else if(a[i]==')'){
if(empty()){
cout<<"NO";
return 0;
}else{
pop();
}
}
if(a[i]=='@') break;
}
if(empty()) cout<<"YES";
else cout<<"NO";
return 0;
}
这里空空如也
有帮助,赞一个