模拟栈

题目链接:https://www.acwing.com/problem/content/830/

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e5+5;
 4 int a[N];
 5 int main()
 6 {
 7     int m;
 8     cin>>m;
 9     int t=0;
10     while(m--){
11         string s;
12         int x;
13         cin>>s;
14         if(s=="push"){
15             cin>>x;
16             a[++t]=x;
17         }else if(s=="query"){
18             cout<<a[t]<<endl;
19         }else if(s=="pop"){
20             --t;
21         }else if(s=="empty"){
22             if(t>0) cout<<"NO"<<endl;
23             else cout<<"YES"<<endl;
24         }
25     }
26     return 0;
27 }

 

posted @ 2022-01-12 09:07  wydxry  阅读(41)  评论(0编辑  收藏  举报
Live2D