You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
557 B

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int stk[N], tt;
int main() {
string op;
int n;
cin >> n;
while (n--) {
cin >> op;
if (op == "push") {
int x;
cin >> x;
stk[++tt] = x;
} else if (op == "pop")
tt--;
else if (op == "query")
printf("%d\n", stk[tt]);
else if (op == "empty") {
if (tt == 0) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}