AcWing 154. 滑动窗口
原题链接
简单
作者:
浮玺君
,
2022-04-28 10:59:49
,
所有人可见
,
阅读 162
#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e6 + 10;
int a[N];
int main()
{
int m;
// 非循环队列一般tt=-1 循环队列一般为tt=0
int hh = 0, tt = -1;
cin >> m;
while( m-- )
{
string str;
cin >> str;
if(str == "push")
{
int x;
cin >> x;
a[++tt] = x;
}
else if(str == "query")
{
cout << a[hh] << endl;
}
else if(str == "pop")
{
// 数组下标由x -> x + 1
hh ++;
}
else if(str == "empty")
{
// 比如hh下标为6 tt下标为5 这样队列已经全部删除完了
if(hh > tt) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
return 0;
}