#include <iostream> #include <vector> using namespace std; class MyStack { vector<int> arr; public: void push(int x) { arr.push_back(x); } void pop() { if (arr.empty()) { cout << "error" << endl; return; } cout<<arr.at(arr.size() - 1)<<endl; arr.pop_back(); } void top() { if (arr.empty()) { cout << "error" << endl; return; } int num = arr.at(arr.size() - 1); cout << num << endl; } }; int main() { int n; cin >> n; MyStack stack; for (int i = 0; i < n; i++) { string op; int num; while (cin >> op) { if (op == "push") { cin >> num; stack.push(num); } else if (op == "pop") { stack.pop(); } else if (op == "top") { stack.top(); } } } return 0; } // 64 位输出请用 printf("%lld")