1. #include <iostream>
    2. using namespace std;
    3. const int N = 100010;
    4. int stk[N],idx,tt = 0;//从0开始,到0时显示栈空
    5. void push(int x){
    6. stk[++ tt] = x;
    7. }
    8. void pop(){
    9. --tt;
    10. }
    11. int empty(){
    12. if(tt==0) return 1;
    13. else return 0;
    14. }
    15. int query(){
    16. return stk[tt];
    17. }
    18. int main(){
    19. int m;
    20. cin >> m;
    21. while(m--){
    22. string op;
    23. cin >> op;
    24. if(op == "push"){
    25. int x;
    26. cin >> x;
    27. push(x);
    28. }else if(op == "pop"){
    29. pop();
    30. }else if(op == "empty"){
    31. if(empty()) cout << "YES" << endl;
    32. else cout << "NO" << endl;
    33. }else{
    34. cout << query() << endl;
    35. }
    36. }
    37. return 0 ;
    38. }