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. 通过IIS寄宿WCF服务

    WCF全面解析一书中的例子S104,直接将Service目录部署到iis是无法得到服务相应的,需要在项目中新建一个web项目,删除掉自动生成的所有文件之后,把Service目录下的Calculator ...

  2. 关Java的内存模型(JMM)

    JMM的关键技术点都是围绕着多线程的原子性.可见性和有序性来建立的 一.原子性(Atomicity) 原子性是指一个操作是不可中断的.即使是在多个线程一起执行的时候,一个操作一旦开始,就不会被其他线程 ...

  3. 【异常】redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'PSETEX'

    在spring中 针对 RedisTemplate类: private RedisTemplate<String, String> template; 当调用下面方法 template.o ...

  4. 2018焦作网络赛Give Candies

    一开始忽略了欧拉定理指数部分是modphi(n-1)没有memset,减法后面没加0:

  5. 使用nginx+dnsmasq解决同IP不同端口Session冲突问题

    由于一台服务器上需要部署多个项目,而我们的WEB项目因为用到框架都是一样的,导致同时运行,session相互冲突,这个登录后,那个就得重新登录,造成了使用不方便,原因是IP相同认为是同一个域,接收了B ...

  6. stl算法:next_permutation剖析

    在标准库算法中,next_permutation应用在数列操作上比较广泛.这个函数可以计算一组数据的全排列.但是怎么用,原理如何,我做了简单的剖析. 首先查看stl中相关信息.函数原型: templa ...

  7. Leetcode 22

    //这题感觉不如前两题回溯清楚,还要再看看class Solution { public: vector<string> generateParenthesis(int n) { vect ...

  8. 决策树ID3算法实现

    决策树的ID3算法基于信息增益来选择最优特征,于是自己实现了一把,直接上代码. """ CreateTime : 2019/3/3 22:19 Author : X Fi ...

  9. Mybatis学习总结-----mybatis中refid是什么意思(十)

    1.首先定义一个sql标签,一定要定义唯一id<sql id="Base_Column_List" >name,age</sql>2.然后通过id引用< ...

  10. learning docker steps(8) ----- docker network 初次体验

    参考: docker network 主要是介绍了docker 容器之间的组网模式, 一般来说实像组网主要是依赖于bridge iptalbes vlan来实现,但是附带的如端口转发会降低效率. 新型 ...