hdu 1702 ACboy needs your help again!

时间:2022-11-11 23:38:16

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1702

ACboy needs your help again!

Description

ACboy was kidnapped!! 
he miss his mother very much and is very scare now.You can't image how dark the room he was put into is, so poor :(.
As a smart ACMer, you want to get ACboy out of the monster's labyrinth.But when you arrive at the gate of the maze, the monste say :" I have heard that you are very clever, but if can't solve my problems, you will die with ACboy."
The problems of the monster is shown on the wall:
Each problem's first line is a integer N(the number of commands), and a word "FIFO" or "FILO".(you are very happy because you know "FIFO" stands for "First In First Out", and "FILO" means "First In Last Out").
and the following N lines, each line is "IN M" or "OUT", (M represent a integer).
and the answer of a problem is a passowrd of a door, so if you want to rescue ACboy, answer the problem carefully!

Input

The input contains multiple test cases.
The first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.

Output

For each command "OUT", you should output a integer depend on the word is "FIFO" or "FILO", or a word "None" if you don't have any integer.

SampleInput

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

SampleOutput

1
2
2
1
1
2
None
2
3

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::set;
using std::map;
using std::pair;
using std::stack;
using std::queue;
using std::vector;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
const int Max_N = ;
typedef unsigned long long ull;
queue<int> que; stack<int> stk;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int n, v, t;
char buf[];
scanf("%d", &t);
while (t--) {
scanf("%d %s", &n, buf);
if ('F' == buf[]) {
rep(i, n) {
scanf("%s", buf);
if ('I' == buf[]) scanf("%d", &v), que.push(v);
else {
if (que.empty()) { puts("None"); continue; }
printf("%d\n", que.front()), que.pop();
}
}
} else {
rep(i, n) {
scanf("%s", buf);
if ('I' == buf[]) scanf("%d", &v), stk.push(v);
else {
if (stk.empty()) { puts("None"); continue; }
printf("%d\n", stk.top()), stk.pop();
}
}
}
while (!stk.empty()) stk.pop(); while (!que.empty()) que.pop();
}
return ;
}