C++
#include <array> #include <iostream> using namespace std; class stack{ private: array<int, 100000> s; int top=-1; public: void push(int x) { s[++top] = x; } void pop() { if (top>-1) top--; else cout << "Empty" << endl; } void query() { if (top>-1) cout << s[top] << endl; else cout << "Empty" << endl; } int size() { return top+1; } }; int main() { int n; cin >> n; string op; int x; stack s; while (n--) { cin >> op; if (op=="push") { cin >> x; s.push(x); } else if (op=="pop") { s.pop(); } else if (op=="query") { s.query(); } else if (op=="size") { cout << s.size() << endl; } } } // 64 位输出请用 printf("%lld")