最简单
2026-08-23 11:11:14
发布于:广东
0阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
stack<int>s;
int main(){
int n;
int x;
cin >> n;
for(int i = 1;i<=n;i++){
string m;
cin >> m;
if(m=="empty"){
if(s.empty()){
cout << "yes" << endl;
}else{
cout << "no" << endl;
}
}else if(m=="push"){
cin >> x;
s.push(x);
}else if(m=="size"){
cout << "size = "<<s.size() << endl;
}else if(m=="top"){
if(s.empty()){
cout << "top fail " << endl;
}else{
cout << "top = " << s.top() << endl;
}
}else{
if(s.empty()){
cout << "pop fail " << endl;
}else{
cout << "pop "<<s.top()<<endl;
s.pop();
}
}
}
return 0;
}
这里空空如也







有帮助,赞一个