AcWing 829. 模拟队列
原题链接
简单
作者:
acw_yxy
,
2020-11-01 13:08:14
,
所有人可见
,
阅读 308
模拟队列
(模拟队列) $O(n)$
C++ 代码
#include <iostream>
#include <string>
using namespace std;
const int N = 100010;
int q[N];
int hh = 0, ll = 0;
int main()
{
cin.tie(0);
std::ios::sync_with_stdio(false);
string command;
int num, temp;
cin >> num;
while(num--)
{
cin >> command;
if(command == "push")
{
cin >> temp;
q[ll++] = temp;
}
else if(command == "pop")
{
if(ll != hh)
hh++;
}
else if(command == "empty")
{
if(ll == hh)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
else
{
if(ll != hh)
cout << q[hh] << endl;
}
}
return 0;
}