HDU - 1702 ACboy needs your help again!(栈和队列)
Description
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 first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.
Output
Sample Input FIFO
IN
IN
OUT
OUT
FILO
IN
IN
OUT
OUT
FIFO
IN
IN
OUT
OUT
OUT
FILO
IN
IN
OUT
IN
OUT
Sample Output None
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1702
*******************************************
题意:题意比较清晰,FIFO则先进先出,FILO则先进后出
分析:简单的队列和栈的应用就好
AC代码
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<algorithm>
#include<time.h>
#include<stack>
using namespace std;
#define N 1000
#define INF 0x3f3f3f3f int main()
{
int T,i,a,n;
char s[N],str[N]; scanf("%d", &T); while(T--)
{
scanf("%d %s", &n , s); if(s[]=='F')///存入队列
{
queue<int >Q;
for(i=;i<n;i++)
{
scanf("%s", str);
if(str[]=='I')
{
scanf("%d", &a);
Q.push(a);
}
else
{
if(Q.empty())
printf("None\n");
else
{
int x=Q.front();
Q.pop();
printf("%d\n", x);
}
}
}
}
else
{
stack<int >P;
for(i=;i<n;i++)
{
scanf("%s", str); if(str[]=='I')
{
scanf("%d",&a);
P.push(a);
}
else
{
if(P.empty())
printf("None\n");
else
{
int x=P.top();
P.pop();
printf("%d\n", x);
}
}
}
}
} return ;
}
HDU - 1702 ACboy needs your help again!(栈和队列)的更多相关文章
- hdu 1702 ACboy needs your help again!
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1702 ACboy needs your help again! Description ACboy w ...
- (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 ...
- HDU 1712 ACboy needs your help(包背包)
HDU 1712 ACboy needs your help(包背包) pid=1712">http://acm.hdu.edu.cn/showproblem.php? pid=171 ...
- queue的使用-Hdu 1702
ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 学习javascript数据结构(一)——栈和队列
前言 只要你不计较得失,人生还有什么不能想法子克服的. 原文地址:学习javascript数据结构(一)--栈和队列 博主博客地址:Damonare的个人博客 几乎所有的编程语言都原生支持数组类型,因 ...
- [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)
再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...
- 剑指Offer面试题:6.用两个栈实现队列
一.题目:用两个栈实现队列 题目:用两个栈实现一个队列.队列的声明如下,请实现它的两个函数appendTail和deleteHead,分别完成在队列尾部插入结点和在队列头部删除结点的功能. 原文是使用 ...
- C实现栈和队列
这两天再学习了数据结构的栈和队列,思想很简单,可能是学习PHP那会没有直接使用栈和队列,写的太少,所以用具体代码实现的时候出现了各种错误,感觉还是C语言功底不行.栈和队列不论在面试中还是笔试中都很重要 ...
- JavaScript数组模拟栈和队列
*栈和队列:js中没有真正的栈和队列的类型 一切都是用数组对象模拟的 栈:只能从一端进出的数组,另一端封闭 FILO 何时使用:今后只要仅希望数组只能从一端进 ...
随机推荐
- SharePoint2013 Excel导出好的代码
C#Excel操作类ExcelHelper.cs 来源:http://www.hellocsharp.com/article/67.aspx C#源码世界 发布于: 2014-09-12 使用本类之前 ...
- android listen
android监听机制,应该是一种观察者模式. 摘抄网上教程,观察者模式的结构如下: 其中涉及的角色有: ● 抽象主题(Subject)角色:抽象主题角色把所有对观察者对象的引用保存在一个聚集(比如A ...
- centos 10字母随机文件病毒清理
病毒表现:网络流量暴满,疯狂地向香港的一个IP发数据,同时在top里面表现为随机的10位字母的进程,看/proc里面的信息,则为ls,cd之类常见的命令,CPU利用率也在top之首.杀死该进程后,会再 ...
- Linux手动搭建LAMP环境
当你看到标题里的“手动搭建”,你是不是会想,难不成还有“自动搭建”?当然......不是,这里的“手动搭建”是指按部就班的搭建Apache.MySQL.PHP环境,是相对于集成软件包而言的.所以你是不 ...
- VirtualBox 不能为虚拟电脑打开一个新的任务 可能的解决方案
1. 在虚拟机上右键,清除保存状态 2.Cannot load R0 module C:\Program Files\Oracle\VirtualBox/VBoxDD2R0.r0: SUPR3Load ...
- 三层交换机配置说明(华为S5700设置三个网段互通)
1.配置Switch # 创建VLAN <HUAWEI> system-view[HUAWEI] sysname Switch[Switch] vlan batch 10 20 30# 配 ...
- 如何查找僵尸进程并Kill之,杀不掉的要查看父进程并杀之
转自:如何查找僵尸进程并Kill之,杀不掉的要查看父进程并杀之 用ps和grep命令寻找僵尸进程#ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'命令注解:-A ...
- DB层级
最上层: 业务层 负载均衡: LVS 代理层: DB-PROXY DB层: DB主库 DB从库 随着DB出 ...
- MJExtension的使用
1. Plist → 模型数组 控制器中引用#import "MJExtension.h" 模型数组 = [模型类名 objectArrayWithFilename:@" ...
- 使用 Eclipse Memory Analyzer 进行简单内存泄漏分析
Java 内存泄露的根本原因: 保存了不可能再被访问的变量类型的引用.因此我们的目的就是要找出这样的引用. 1.测试代码: public class MainActivity extends Acti ...