#include <iostream> #include <cstdio> #include <stack> using namespace std; /** * 堆栈的使用 * @return */ int main() { int n; while (cin >> n) { stack<int> stack; for (int i = 0; i < n; ++i) { char instruction; cin >> instruction; if (instruction == 'P') { int num; cin >> num; stack.push(num); } else if (instruction == 'O') { if (!stack.empty()) { stack.pop(); } } else { if (stack.empty()) { cout << "E" << endl; } else { cout << stack.top() << endl; } } } } return 0; }