4 4 FIFO IN 1 IN 2 OUT OUT 4 FILO IN 1 IN 2 OUT OUT 5 FIFO IN 1 IN 2 OUT OUT OUT 5 FILO IN 1 IN 2 OUT IN 3 OUT
1 2 2 1 1 2 None 2 3
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<queue>
#include<stack>
using namespace std;
char c[10];
int x;
void solve_s(int n)
{
stack<int>s;
while(n--)
{
scanf("%s",c);
if(!strcmp(c,"IN"))
{
scanf("%d",&x);
s.push(x);
}
else
{
if(!s.empty())
{
printf("%d\n",s.top());
s.pop();
}
else
printf("None\n");
}
}
}
void solve_q(int n)
{
queue<int>q;
while(n--)
{
scanf("%s",c);
if(!strcmp(c,"IN"))
{
scanf("%d",&x);
q.push(x);
}
else
{
if(!q.empty())
{
printf("%d\n",q.front());
q.pop();
}
else
printf("None\n");
}
}
}
int main()
{
int t,n;
char str[10];
scanf("%d",&t);
while(t--)
{
scanf("%d%s",&n,str);
if(!strcmp(str,"FIFO"))
solve_q(n);
else
solve_s(n);
}
return 0;
}
HDU 1702 ACboy needs your help again!,布布扣,bubuko.com
HDU 1702 ACboy needs your help again!
原文:http://blog.csdn.net/u013582254/article/details/38412379