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
分别定义一个栈和一个队列,输入FIFO即先入先出,操作队列,输入FILO即先入后出,操作栈。
 1 #include<iostream>
2 #include<stack>
3 #include<queue>
4 using namespace std;
5 int main()
6 {
7 stack<int> s;
8 queue<int> q;
9 int n;
10 cin>>n;
11 while(n--)
12 {
13 int m;
14 string s1;
15 cin>>m>>s1;
16 while(!s.empty())s.pop();//循环开始清空栈和队列
17 while(!q.empty())q.pop();
18 if(s1=="FIFO")//先入先出操作队列
19 {
20 for(int i=0;i<m;i++)
21 {
22 string s2;int num;
23 cin>>s2;
24 if(s2=="IN"){cin>>num;q.push(num);}//入队
25 if(s2=="OUT"){
26 if(q.empty())cout<<"None"<<endl;//队列为空不能"OUT",输出None
27 else
28 {
29 cout<<q.front()<<endl;//q.front()取队头值
30 q.pop();//无返回值,借助q.front()获得队头值
31 }
32 }
33 }
34 }
35 if(s1=="FILO")
36 {
37 for(int i=0;i<m;i++)
38 {
39 string s2;int num;
40 cin>>s2;
41 if(s2=="IN"){cin>>num;s.push(num);}//入栈
42 if(s2=="OUT"){
43 if(s.empty())cout<<"None"<<endl;//栈为空时
44 else
45 {
46 cout<<s.top()<<endl;s.pop();//s.pop()无返回值,借助s.top()获得栈顶元素
47 }
48
49 }
50 }
51 }
52
53 }
54 return 0;
55 }

STL练习-ACboy needs your help again!的更多相关文章

  1. (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 ...

  2. 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 ( ...

  3. hdu1702 ACboy needs your help again![简单STL 栈 队列]

    目录 题目地址 题干 代码和解释 参考 题目地址 hdu1702 题干 代码和解释 本题很简单,只要掌握STL stack和STL vector的语法即可作答.记录本题是为了记录STL vector的 ...

  4. stl 题目总结

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

  5. 详细解说 STL 排序(Sort)

    0 前言: STL,为什么你必须掌握 对于程序员来说,数据结构是必修的一门课.从查找到排序,从链表到二叉树,几乎所有的算法和原理都需要理解,理解不了也要死记硬背下来.幸运的是这些理论都已经比较成熟,算 ...

  6. STL标准模板库(简介)

    标准模板库(STL,Standard Template Library)是C++标准库的重要组成部分,包含了诸多在计算机科学领域里所常见的基本数据结构和基本算法,为广大C++程序员提供了一个可扩展的应 ...

  7. STL的std::find和std::find_if

    std::find是用来查找容器元素算法,但是它只能查找容器元素为基本数据类型,如果想要查找类类型,应该使用find_if. 小例子: #include "stdafx.h" #i ...

  8. STL: unordered_map 自定义键值使用

    使用Windows下 RECT 类型做unordered_map 键值 1. Hash 函数 计算自定义类型的hash值. struct hash_RECT { size_t operator()(c ...

  9. C++ STL简述

    前言 最近要找工作,免不得要有一番笔试,今年好像突然就都流行在线笔试了,真是搞的我一塌糊涂.有的公司呢,不支持Python,Java我也不会,C有些数据结构又有些复杂,所以是时候把STL再看一遍了-不 ...

  10. codevs 1285 二叉查找树STL基本用法

    C++STL库的set就是一个二叉查找树,并且支持结构体. 在写结构体式的二叉查找树时,需要在结构体里面定义操作符 < ,因为需要比较. set经常会用到迭代器,这里说明一下迭代器:可以类似的把 ...

随机推荐

  1. SICP 笔记:环境配置

    SICP 笔记:环境配置 记录学习<算机的程序的构造和解释>的笔记. 环境配置 SICP 里面使用的语言是一种 Lisp 的变体 Scheme. 使用 DrRacket 作为 IDE 来进 ...

  2. 修改文件时mmap如何处理

    拷贝二进制(elf)文件 在拷贝二进制文件的时候,如果文件是一个可执行文件,并且有一个进程在运行这个可执行文件,那么拷贝的时候会出现"文本忙"(ETXTBSY)的错误提示,并且拷贝 ...

  3. unity 资源打包,MD5值计算注意点

    仅作记录: unity3d在修改资源时,有些类型的资源修改的是源文件,比如:fbx,mp3,.jpg,.png等.这些资源是外部资源导入unity3d中,untiy3d导入编译时,生成相应的meta文 ...

  4. oracl ocp认证到底有没有用!!!

    从一个网友听说有个OCP专家认证,我们本地也有,要1万3,问题是我想真的学东西而不是为了考证,不知道这个培训能学到多少呀.

  5. Windows安装MySQL5.7配置

    1.下载对应版本安装包,http://dev.mysql.com/downloads/mysql 2.将安装包解压 3.解压后会发现没有my.ini文件,此版本并不需要手动创建my.ini文件,手动创 ...

  6. form 常用

    1.input输入数字校验 <el-input class="timeRange" type="number" v-model="value & ...

  7. centos7 部署 DNS 主从

    centos7 部署 DNS 主从 环境 名称 ip地址 cpu 内存 yz-dns-master 10.148.100.81 4c 8G yz-dns-slave 10.148.100.82 4c ...

  8. 实现一个网页同时调用多个倒计时 jquery/js

    最近需要网页添加多个倒计时. 查阅网络,基本上都是千遍一律的不好用. 自己按需写了个.希望对大家有用. 有用请赞一个哦! //js2 var plugJs={ stamp:0, tid:1, stam ...

  9. NIO 缓冲区 ByteBuffer 基本认识

    一.差别 java.nio.HeapByteBuffer 0. 获取方式:ByteBuffer.allocate(int value); 1. java堆内存,读写效率较低,但分配内存较块. 2. 受 ...

  10. C# IOC 个人理解

    学习QFramework 过程中发现对IOC不太了解,就大概百度了一下思路 将原先类与类之间的相互依赖关系,转移到第三方容器中, 同过读取配置文件来生成对应的依赖关系,将原本类之间的耦合转移到配置文件 ...