直接用占
2026-08-01 09:50:16
发布于:四川
0阅读
0回复
0点赞
#include<iostream>
#include<stack>
using namespace std;
int t,x;
string s;
stack<int>st;
int main(){
cin>>t;
while(t--){
cin>>s;
if(s=="empty"){
if(st.empty()) cout<<"yes"<<'\n';
else cout<<"no"<<'\n';
}else if(s=="pop"){
if(!st.empty()){
cout<<"pop "<<st.top()<<'\n';
st.pop();
}else cout<<"pop fail"<<'\n';
}else if(s=="push"){
cin>>x;
st.push(x);
}else if(s=="top"){
if(!st.empty()) {
cout<<"top = "<<st.top()<<'\n';
}else cout<<"top fail"<<'\n';
}else {
cout<<"size = "<<st.size()<<'\n';
}
}
return 0;
}
这里空空如也






有帮助,赞一个