AcWing 828. 模拟栈
原题链接
简单
作者:
piaofan
,
2021-01-25 09:11:29
,
所有人可见
,
阅读 245
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int stk[maxn], base, top;
void pu (int x) { stk[top++] = x; }
void po () { top--; }
bool em () { return top == base; }
int qu() { return stk[top-1];}
int main (void) {
int m, x;
string s;
cin >> m;
while (m--) {
cin >> s;
if (s == "push") { cin >> x; pu(x); }
else if (s == "pop") po();
else if (s == "empty") {
if (em()) cout << "YES" << endl;
else cout << "NO" << endl;
} else if (s == "query") cout << qu() << endl;
}
return 0;
}