题解
2026-09-06 09:44:54
发布于:江西
6阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
stack<int> a;
int main(){
int n;
cin >> n;
for ( int i=0; i<n; i++){
string s;
cin >> s;
if ( s[0] == 'e'){
cout << (a.empty()?"yes":"no") << endl;
}else if ( s[0] == 'p'){
if ( s[1] == 'u'){
int x;
cin >> x;
a.push(x);
}else{
if ( a.empty()){
cout << "pop fail" << endl;
}else{
cout << "pop " << a.top() << endl;
a.pop();
}
}
}else if ( s[0] == 't'){
if ( a.empty()){
cout << "top fail" << endl;
}else{
cout << "top = " << a.top() << endl;
}
}else if ( s[0] == 's'){
cout << "size = " << a.size() << endl;
}
}
}
这里空空如也


有帮助,赞一个