多学习。

【队列】数组模拟(AcWing829.模拟队列)

AcWing829.模拟队列

#include <iostream>

using namespace std;

const int N = 1e5+10;

int q[N], hh, tt;

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