又臭又长的一坨代码
2025-03-15 10:47:30
发布于:浙江
0阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int main(){
stack<int>st;
string s;
int n;
cin>>n;
while(n--){
cin>>s;
if(s=="empty"){
if(st.empty()){cout<<"yes";}
else{cout<<"no";}
cout<<endl;
}
else if(s=="push"){
int m;
cin>>m;
st.push(m);
}
else if(s=="size"){cout<<"size = "<<st.size()<<endl;}
else if(s=="top"){
if(st.empty()){cout<<"top fail";}
else{cout<<"top = "<<st.top();}
cout<<endl;
}
else if(s=="pop"){
if(st.empty()){cout<<"pop fail";}
else{
cout<<"pop "<<st.top();
st.pop();}
cout<<endl;
}
}
return 0;
}
//速度前7% 内存前70% 真巧
这里空空如也
有帮助,赞一个