题解 | #堆栈的使用#
堆栈的使用
https://www.nowcoder.com/practice/e91982a145944ceab6bb9a4a508e0e26
#include <iostream> #include <stack> using namespace std; stack<int> stk; int main() { int n; while (cin >> n) { char op; int num; while(n --){ cin >> op; if(op == 'P'){ cin >> num; stk.push(num); } else if (op == 'A') { if(!stk.empty()) cout << stk.top() << endl; else cout << 'E' << endl; } else if (op == 'O'){ if(!stk.empty()) stk.pop(); } } } return 0; } // 64 位输出请用 printf("%lld")