AcWing 828. 模拟栈

时间:2020-07-29 15:11:00   收藏:0   阅读:89

AcWing 828. 模拟栈


#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int stk[N],tt;
void init(){
    tt=0;
}
void add(int x){
    stk[++tt]=x;
}
void remove(){
    tt--;
}
int main(){
    int m;
    cin>>m;
    init();
    while(m--){
        string op;
        cin>>op;
        int x;
        if(op=="push"){
            scanf("%d",&x);
            add(x);
        }else if(op=="pop"){
            remove();
        }else if(op=="empty"){
            if(tt) cout<<"NO"<<endl;
            else cout<<"Yes"<<endl;
        }else if(op=="query"){
            cout<<stk[tt]<<endl;
        }
    }
    return 0;
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!