AcWing 828. 模拟栈
原题链接
简单
作者:
pta
,
2022-04-21 20:07:57
,
所有人可见
,
阅读 177
C++ 代码
#include<iostream>
using namespace std;
const int N = 100010;
int stk[N];
int tt;
void push(int x){
a[++ tt] = x;
}
void pop(){
tt --;
}
int query(){
return stk[tt];
}
bool empty(){
if(!tt) return true;
else return false;
}
int main(){
int m;
cin >> m;
while(m --){
string op;
int x;
cin >> op;
if(op == "push"){
cin >> x;
push(x);
}
else if(op == "pop"){
pop();
}
else if(op == "empty"){
if(empty()) printf("YES\n");
else printf("NO\n");
}
else {
cout << query() << endl;
}
}
return 0;
}
blablabla