题解 | #堆栈的使用#
堆栈的使用
https://www.nowcoder.com/practice/e91982a145944ceab6bb9a4a508e0e26
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
char op;
while(cin >> n){
stack<int> s;
while(n --){
cin >> op;
if(op == 'P'){
cin >> m;
s.push(m);
} else if(op == 'A'){
if(!s.empty()){
cout << s.top() << endl;
} else {
cout << 'E' << endl;
}
} else if(op == 'O'){
if(!s.empty())s.pop();
}
}
}
return 0;
}
查看3道真题和解析