ACboy needs your help again!

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10095    Accepted Submission(s): 5066


Problem 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.
 

Sample Input

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
 

Sample Output

1
2
2
1
1
2
None
2
3
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1701 1700 1703 1704 1706 

每组数据结束后,记得把队列/栈清空,否则会wa

empty()用来检查队列/栈是否为空,为空返回true

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int main()
{
int t,n,m;
char ch[50],sh[50];
cin>>t;
queue<int>que;
stack<int>s;
while(t--)
{
while(!s.empty()) s.pop();
while(!que.empty()) que.pop();//直到队列/栈空的时候,停止操作
cin>>n>>ch;
if(strcmp(ch,"FIFO")==0)
{
for(int i=0;i<n;i++)
{ cin>>sh;
if(strcmp(sh,"IN")==0)
{
cin>>m;
que.push(m);
}
if(strcmp(sh,"OUT")==0)
{
if(que.size()>0)
{
cout<<que.front()<<endl;
que.pop();
}
else cout<<"None\n";
}
}
}
if(strcmp(ch,"FILO")==0)
{
for(int i=0;i<n;i++)
{ cin>>sh;
if(strcmp(sh,"IN")==0)
{
cin>>m;
s.push(m);
}
if(strcmp(sh,"OUT")==0)
{
if(s.size()>0)
{
cout<<s.top()<<endl;
s.pop();
}
else cout<<"None\n";
}
}
}
}
return 0;
}

HDU1702:ACboy needs your help again!的更多相关文章

  1. HDU1712:ACboy needs your help(分组背包)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1712 解释看这里:http://www.cnblogs.com/zhangmingcheng/p/3940 ...

  2. 分组背包 例题:hdu 1712 ACboy needs your help

    分组背包需求 有N件物品,告诉你这N件物品的重量以及价值,将这些物品划分为K组,每组中的物品互相冲突,最多选一件,求解将哪些物品装入背包可使这些物品的费用综合不超过背包的容量,且价值总和最大. 解题模 ...

  3. (hdu step 8.1.1)ACboy needs your help again!(STL中栈和队列的基本使用)

    题目: ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...

  4. STL专题

    一.algorithm 1.sort 问题1:给你n个整数,请按从大到小的顺序输出其中前m大的数. Input:每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二 ...

  5. stl 题目总结

    stl 题目总结 一.圆桌问题 1 .问题: 圆桌上围坐着2n个人.其中n个人是好人,另外n个人是坏人.如果从第一个人开始数数,数到第m个人,则立即处死该人:然后从被处死的人之后开始数数,再将数到的第 ...

  6. java web 开发三剑客 -------电子书

    Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...

  7. 所有selenium相关的库

    通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...

  8. ACboy needs your help again!--hdu1702

    ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. hdu1702 ACboy needs your help again!(栈处理)

    ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

随机推荐

  1. jdk1.8

    Jdk1.8新特性 毫无疑问,Java 8是Java自Java 5(发布于2004年)之后的最重要的版本.这个版本包含语言.编译器.库.工具和JVM等方面的十多个新特性.在本文中我们将学习这些新特性, ...

  2. Codeforces B - Tavas and SaDDas

    535B - Tavas and SaDDas 方法一:打表大法. 代码1: #include<bits/stdc++.h> using namespace std; ]={,,,,,,, ...

  3. Jersey 2.x 运行项目

    现在我们已经有可以可以运行的项目了,让我们队这个项目进行一些测试吧. 你需要运行下面的一些命令行: mvn clean test 这个命令将会对项目进行编译后运行单元测试. 你应该会看到和下面类似的输 ...

  4. SPFA 最短路

    求单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm.     SPFA算法是西南交通大学段凡丁于1994年发表的.    从名字我们就可以看出,这种算法在 ...

  5. spring PROPAGATION

    PROPAGATION_REQUIRED Support a current transaction; create a new one if none exists.  支持一个当前事务;如果不存在 ...

  6. Oracle 使用GSON库解析复杂json串

    在前文中讲到了如何使用JSON标准库解析json串,参考: Oracle解析复杂json的方法(转) 现补充一篇使用GSON库在Oracle中解析复杂json的方法. GSON串的使用教程参考官方文档 ...

  7. JavaScript In OA Framework

    原文地址:JavaScript In OA Framework (需FQ) “To be or not to be…… is the question…..!” The famous soliloqu ...

  8. OC Copy基本使用(深拷贝和浅拷贝)

     首先,什么是copy? Copy的字面意思是“复制”.“拷贝”,是一个产生副本的过程. 常见的复制有:文件复制,作用是利用一个源文件产生一个副本文件. 特点:1.修改源文件的内容,不会影响副本文件: ...

  9. shell批量杀进程

    ps aux |grep java |grep -v 'grep java'|awk {'print $2'}|xargs kill -9 ps aux |grep java 查询包含‘java’的进 ...

  10. PHP:第三章——数组中的array_values

    例: <?php header("Content-Type:text/html;charset=utf-8"); //array_value(); //功能:返回数组中所有的 ...