【典中典】栈
AcWing 828. 模拟栈
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int stk[N], top = 0, t;
char op[8];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%s", op);
if (op[0] == 'p' && op[1] == 'u') {
scanf("%d", &stk[++top]);
} else if (op[1] == 'o') {
top--;
} else if (op[1] == 'm') {
puts(top ? "NO" : "YES");
} else {
printf("%d\n", stk[top]);
}
}
return 0;
}