3.3 队列和queue
1.头文件
#include<queue>
2.有关操作
queue<int/float/char...>a;
q.push(n);
q.front();
q.pop();
q.back();
q.size();
q.empty();
3.例题
hdu 1702
http:
#include<bits/stdc++.h>
using namespace std;
int t,n,temp;
int main()
{
cin>>t;
while(t--)
{
string str,str1;
queue<int>Q;
stack<int>S;
cin>>n>>str;
for(int i=0;i<n;i++)
{
if(str=="FIFO")
{
cin>>str1;
if(str1=="IN")
{
scanf("%d",&temp);
Q.push(temp);
}
if(str1=="OUT")
{
if(Q.empty()) printf("NONE\n");
else printf("%d\n",Q.front()),Q.pop();
}
}
else
{
cin>>str1;
if(str1=="IN")
{
scanf("%d",&temp);
S.push(temp);
}
if(str1=="OUT")
{
if(Q.empty()) printf("NONE\n");
else printf("%d\n",S.top()),S.pop();
}
}
}
}
return 0;
}