最最简单的题解!!!!!!!!!!!!!
2026-08-26 09:22:16
发布于:四川
4阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
stack<int>a;
string s;
cin>>s;
if(s=="empty"){
if(a.empty()==1){
cout<<"yes"<<endl;
}else{
cout<<"no"<<endl;
}
}else if(s=="push"){
int x;
cin>>x;
a.push(x);
}else if(s=="size"){
cout<<"size = "<<a.size()<<endl;
}else if(s=="top"){
if(a.empty()==0){
cout<<"top = "<<a.top()<<endl;
}else{
cout<<"top fail"<<endl;
}
}else if(s=="pop"){
if(a.empty()==0){
int f=a.top();
a.pop();
cout<<"pop "<<f<<endl;
}else{
cout<<"pop fail"<<endl;
}
}
}
return 0;
}
点个赞吧,就当积德了
全部评论 1
顶!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
(帮帮主包)3天前 来自 四川
0


有帮助,赞一个