【栈】数组模拟(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;
}

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号