hdu-1702-栈和队列
ACboy needs your help again!
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12994 Accepted Submission(s): 6407
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!
The first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.
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
2
2
1
1
2
None
2
3
#include<iostream>
#include<string.h>
#include<queue>
#include<stack>
using namespace std;
queue<int>a;
stack<int>b;
int main()
{
int n,t,x;
char str[],s[];
cin>>n;
while(n--)
{
cin>>t>>str;
if(strcmp(str,"FIFO")==)
{
for(int i=;i<t;i++)
{
cin>>s;
if(strcmp(s,"IN")==)
{
cin>>x;
a.push(x);
}
else
{
if(a.empty())
cout<<"None"<<endl;
else
{
cout<<a.front()<<endl;
a.pop();
}
}
}
while(!a.empty())
a.pop();
}
else
{
for(int i=;i<t;i++)
{
cin>>s;
if(strcmp(s,"IN")==)
{
cin>>x;
b.push(x);
}
else
{
if(b.empty())
cout<<"None"<<endl;
else
{
cout<<b.top()<<endl;
b.pop();
}
}
}
while(!b.empty())
b.pop();
}
} return ;
}
hdu-1702-栈和队列的更多相关文章
- hdu 1702 栈和队列的简单应用
#include<stdio.h> #include<string.h> #include<queue> #include<stack> using n ...
- (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 ...
- 学习javascript数据结构(一)——栈和队列
前言 只要你不计较得失,人生还有什么不能想法子克服的. 原文地址:学习javascript数据结构(一)--栈和队列 博主博客地址:Damonare的个人博客 几乎所有的编程语言都原生支持数组类型,因 ...
- [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)
再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...
- 剑指Offer面试题:6.用两个栈实现队列
一.题目:用两个栈实现队列 题目:用两个栈实现一个队列.队列的声明如下,请实现它的两个函数appendTail和deleteHead,分别完成在队列尾部插入结点和在队列头部删除结点的功能. 原文是使用 ...
- C实现栈和队列
这两天再学习了数据结构的栈和队列,思想很简单,可能是学习PHP那会没有直接使用栈和队列,写的太少,所以用具体代码实现的时候出现了各种错误,感觉还是C语言功底不行.栈和队列不论在面试中还是笔试中都很重要 ...
- JavaScript数组模拟栈和队列
*栈和队列:js中没有真正的栈和队列的类型 一切都是用数组对象模拟的 栈:只能从一端进出的数组,另一端封闭 FILO 何时使用:今后只要仅希望数组只能从一端进 ...
- 用JS描述的数据结构及算法表示——栈和队列(基础版)
前言:找了上课时数据结构的教程来看,但是用的语言是c++,所以具体实现在网上搜大神的博客来看,我看到的大神们的博客都写得特别好,不止讲了最基本的思想和算法实现,更多的是侧重于实例运用,一边看一边在心里 ...
- JavaScript中的算法之美——栈、队列、表
序 最近花了比较多的时间来学习前端的知识,在这个期间也看到了很多的优秀的文章,其中Aaron可能在这个算法方面算是我的启蒙,在此衷心感谢Aaron的付出和奉献,同时自己也会坚定的走前人这种无私奉献的分 ...
- Java数据结构和算法之栈与队列
二.栈与队列 1.栈的定义 栈(Stack)是限制仅在表的一端进行插入和删除运算的线性表. (1)通常称插入.删除的这一端为栈顶(Top),另一端称为栈底(Bottom). (2)当表中没有元素时称为 ...
随机推荐
- Django--form生成select标签
需求 Django--form表单中的select生成方法,如果select中的选项不固定,需要怎么操作. 速查 1.固定select选项 forms 1 2 3 class 表单类名称(forms. ...
- easyui-tabs 页签绑定click事件,动态加载jqgrid
.前台代码 <%-- builed by manage.aspx.cmt [ver:] at // :: --%> <%@ Page Language="C#" ...
- asp.net web 自定义控件
0.调用代码 protected override void Page_Load(object sender, EventArgs e) { //给基类服务接口复制,可不付 if (IsPostBac ...
- 第十三课 Actionlib(2)
上节课讲到了客户端,这节课讲解一下服务器 1.创建服务器源文件touch fibonacciserver.cpp 2.编写源文件 3.修改CMakeLists.txt 4.编译之catkin_make ...
- 简单基础路径配置(单用JSP)EASYUI
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- POJ1062 昂贵的聘礼(带限制的spfa)
Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低 ...
- 今天遇到的传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确的解决方案
传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确.参数 3 ("@UserName"): 数据类型 0xE7 的数据长度或元数据长度无效. 今天在做数据同步的时候遇 ...
- C#多线程编程实战1.4终止线程
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- PHP删除目录
function delDir($directory) { if(file_exists($directory)) { $dir_handle = @opendir($directory); if($ ...
- 二、安装Node.js和npm
1.Note的各个版本官方下载地址: https://nodejs.org/en/download/releases/ 这里我们选择7.6版本为例进行下载安装: 根据自己的情况下载对应的msi安装包 ...