#include<iostream>
#include<stdio.h>
#include<queue>
#include<stack>
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
int casen;
scanf("%d",&casen);
while(casen--)
{
int num;char str[20];
scanf("%d %s",&num,str);
//判断是字符串是队列不是
if(str[2]=='F')
{
queue<int> q;
while(num--)
{
char command[20];
scanf("%s",command);
//如果是输入的话
if(command[0]=='I')
{
int temp;
scanf("%d",&temp);
q.push(temp);
}
//如果是输出的话
else
{
if(q.empty())
{
cout<<"None"<<endl;
}
else
{
cout<<q.front()<<endl;
q.pop();
}
}
}
}
//如果是堆栈的话
else
{
stack<int> s;
while(num--)
{
char command[20];
scanf("%s",command);
//如果是输入的话
if(command[0]=='I')
{
int temp;
scanf("%d",&temp);
s.push(temp);
}
//如果是输出的话
else
{
if(s.empty())
{
cout<<"None"<<endl;
}
else
{
cout<<s.top()<<endl;
s.pop();
}
}
}
}
}
return 0;
}
hdoj 1702 (不解释)
最新推荐文章于 2021-05-27 22:28:25 发布