题解 | #堆栈的使用#
堆栈的使用
https://www.nowcoder.com/practice/e91982a145944ceab6bb9a4a508e0e26
#include <bits/stdc++.h>
using namespace std;
stack<int> stk;
int main(){
int n;
while (cin >> n){
while (n --){
string op;
cin >> op;
if (op == "P"){
int x;
cin >> x;
stk.push(x);
}
else if (op == "O"){
if (!stk.empty()) stk.pop();
}
else{
if (stk.empty()) puts("E");
else printf("%d\n", stk.top());
}
}
}
return 0;
}
查看12道真题和解析