hdu 1702 ACboy needs your help again!
题目连接
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 ;
}
hdu 1702 ACboy needs your help again!的更多相关文章
- HDU - 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 ...
- HDU 1712 ACboy needs your help(包背包)
HDU 1712 ACboy needs your help(包背包) pid=1712">http://acm.hdu.edu.cn/showproblem.php? pid=171 ...
- hdu 1712 ACboy needs your help
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1712 ACboy needs your help 分组背包
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem ...
- HDU 1712 ACboy needs your help 典型的分组背包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 ACboy needs your help Time Limit: 1000/1000 MS ( ...
- HDU 1712 ACboy needs your help (分组背包模版题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...
- hdoj 1702 ACboy needs your help again!【数组模拟+STL实现】
ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 1712 ACboy needs your help(分组背包入门题)
http://acm.hdu.edu.cn/showproblem.php?pid=1712 题意: 有个人学习n门课程,a[i][j]表示用j分钟学习第i门课程所能获得的价值,背包容量为一共有m时间 ...
- queue的使用-Hdu 1702
ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- 没有终结点在侦听可以接受消息的*这通常是由于不正确的地址或者 SOAP操作导致的
引发原因:项目启动时,前端调用 wcf地址,引用的地址访问无法在 IIS Express找到导致该错误 解决方法,找出前端的web.config 查看引用的项目是什么地址开头,如 localho ...
- Could not find action or result
[WARN ] 2013-11-21 14:08:16 :Could not find action or resultThere is no Action mapped for namespace ...
- 虚拟内存和swap分区的关系
首先,这两个概念分别对应windows和linux,即:windows:虚拟内存linux:swap分区 windows即使物理内存没有用完也会去用到虚拟内存,而Linux不一样 Linux只有当物理 ...
- Java程序员面试宝典——重要习题整理
1.下面程序的输出结果是() public class Test { public static void main(String[] args) { int j = 0 ; for(int i = ...
- .NET本质论(4)应用程序对象HttpApplication
当HttpContext对象创建之后,HttpRuntime将随后创建一个用于处理请求的对象,这个对象的类型为HttpApplication. 在ASP.NET内部,HttpRuntime管理一个定 ...
- UTC格式转换 & 十六进制换算为十进制
UTC格式转换成北京时间格式: /// <summary> /// UTC格式与datatime的转换 /// </summary> /// <param name=&q ...
- 线程中CreateEvent和SetEvent及WaitForSingleObject的用法
首先介绍CreateEvent是创建windows事件的意思,作用主要用在判断线程退出,线程锁定方面. CreateEvent 函功能描述:创建或打开一个命名的或无名的事件对象. EVENT有两种状态 ...
- (笔记)angular 单选选项卡
- win7启动文件修复
1:在xp下运行bcdedit.exe(这软件在windows 7的系统盘下 就在你的c:\windows\system32\这里2:将这软件复制到c盘根目录下3:进入命令提示符 输入 c:4:输入 ...
- [原]SQL_实验2.1.3 清华大学出版社
本文出自:http://blog.csdn.net/svitter 实验目标:熟悉实体完整性,参照完整性,事务的处理: /*1.在数据库school表中建立表Stu_uion,进行主键约束,在没有违反 ...