数组模拟栈
#include<iostream>
#include<string>
using namespace std;
const int N = 100010;
int st[N];
int top = -1;
int n, x;
void push(int x) {
st[ ++ top] = x;
}
void pop() {
top -- ;
}
string empty() {
if (top == -1) return "YES";
else return "NO";
}
int query() {
return st[top];
}
int main() {
cin >> n;
while (n -- ) {
string opt;
cin >> opt;
if (opt == "push") {
cin >> x;
push(x);
}
if (opt == "pop") pop();
if (opt == "empty") cout << empty() << endl;
if (opt == "query") cout << query() << endl;
}
}