多学习。

【栈】数组模拟(AcWing828.模拟栈)

AcWing828.模拟栈


#include <iostream>

using namespace std;

const int N = 1e5+10;

int stk[N], tt;

int main()
{
    int n, k;
    cin >> n;
    string c;
    while(n -- )
    {
        cin >> c;
        if(c == "push")
        {
            cin >> k;
            stk[++ tt] = k;
        }
        else if(c == "pop") -- tt ;
        else if(c == "empty") cout << (tt == 0 ? "YES":"NO") <<endl;
        else cout << stk[tt] << endl;
    }
    return 0;
}
posted @ 2022-05-11 19:22  czyaaa  阅读(38)  评论(0)    收藏  举报