题干:

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

解题报告:

按照题意模拟栈和队列就可以了。

AC代码:

#include<bits/stdc++.h>using namespace std;int main()
{int t,tmp;cin>>t;char op[15];while(t--) {int m;scanf("%d",&m);scanf("%s",op);if(!strcmp(op,"FIFO")) {queue<int > q;while(m--) {scanf("%s",op);if(op[0] == 'I') {scanf("%d",&tmp);q.push(tmp);}else {if(q.empty()) printf("None\n");else {printf("%d\n",q.front());q.pop();}}}}else {stack<int > sk;while(m--) {scanf("%s",op);if(op[0] == 'I') {scanf("%d",&tmp);sk.push(tmp);}else {if(sk.empty()) printf("None\n");else {printf("%d\n",sk.top());sk.pop();}}}}}return 0 ;
} 

【HDU - 1702 】ACboy needs your help again! (栈和队列,水题模拟)相关推荐

  1. HDU 1702 ACboy needs your help again!(模拟两种数据结构)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1702 ACboy needs your help again! Time Limit: 1000/10 ...

  2. 数据结构51题之栈和队列18题

    创作不易,点个关注加个收藏再走,防止找不到 目录 一.栈系列基础8道题 1.顺序栈的建立 2.顺序栈的入栈 3.顺序栈的出栈 4.顺序栈栈顶元素的获取 5.链栈的建立 6.链栈的入栈 7.链栈的出栈 ...

  3. 【HDU - 1870】愚人节的礼物(水题模拟 思想类似于栈?)

    题干: 四月一日快到了,Vayko想了个愚人的好办法--送礼物.嘿嘿,不要想的太好,这礼物可没那么简单,Vayko为了愚人,准备了一堆盒子,其中有一个盒子里面装了礼物.盒子里面可以再放零个或者多个盒子 ...

  4. HDU - 1847 Good Luck in CET-4 Everybody!(sg函数,水题)

    题目链接:点击查看 题目大意:给出n张牌,两个人轮流摸牌,每次只能摸2的幂次,问先手必胜还是必败 题目分析:简单sg打表题,先预处理出sg表,然后O(1)查询即可 #include<iostre ...

  5. HDU - 1757 A Simple Math Problem(矩阵快速幂,水题)

    题目链接:点击查看 题目大意:实现公式: f(x)=x,x<10 f(x)=a0*f(x-1)+a1*f(x-2)+--+a9*f(x-10) 题目给出a0~a9,一个n和一个m,要求输出f(n ...

  6. HDU 5776 sum (BestCoder Round #85 A) 简单前缀判断+水题

    分析:就是判断简单的前缀有没有相同,注意下自身是m的倍数,以及vis[0]=true; #include <cstdio> #include <cstdlib> #includ ...

  7. 【HDU - 2398 】Savings Account (水题模拟)

    题干: Suppose you open a savings account with a certain initial balance. You will not make any withdra ...

  8. 12.18栈、队列练习题

    12.18栈.队列练习题 要求: 栈和队列是线性数据结构的代表,结构简单,易于理解. 1.Noi网站上的必须全做完. 2.codevs上栈和队列的所有等级题全部做 3.线性结构中有个知识点是哈希,12 ...

  9. 我幼儿园的弟看了都直呼简单的【栈和队列】

    目录 1. 栈 1.1 栈的概念及结构 1.2 实现栈 2. 队列 2.1 队列的概念及结构 2.2 队列的实现 3. 概念选择题 4. 栈和队列OJ题 4.1 括号匹配问题 4.2 用队列实现栈 4 ...

最新文章

  1. 什么是 Canny 边缘检测算法?
  2. ActiveSync合作关系对话框的配置
  3. ML之LoR:利用LoR二分类之非线性决策算法案例应用之划分正负样本
  4. 建议收藏!一文走遍机器学习的6个主流模型
  5. windows局域网文件共享的使用
  6. neo4j cypher_Neo4j:Cypher –避免热切
  7. [高性能javascript笔记]1-加载和执行
  8. 学习和研究下unity3d的四元数 Quaternion
  9. leetcode解题报告:Interleaving String
  10. 大前端主题添加强力推荐和联系我们模块
  11. javascript 推拉式菜单
  12. Java程序员职业发展规划和方向有哪些?
  13. 命令与征服4 You might have build the wrong LOD level 错误
  14. MySQL 性能优化参数分析
  15. 《弦理论》--笔记读后感
  16. 数十亿红包,正谋杀我们的春节
  17. 微信授权,修改本地 host
  18. 极地漩涡袭美中西部致多人死 芝加哥六成航班取消
  19. Unity灯光渲染之自发光材质
  20. 产生冠军(HDU1002)谢庆皇

热门文章

  1. 【数据结构与算法】【算法思想】【联系与区别】回溯 贪心 动态规划 分治
  2. BlueTooth 蓝牙音频音质探讨
  3. miui12怎么自定义开机动画_MIUI12正式发布:视觉/功能大升级
  4. mysql数据备份在哪里_mysql之数据备份与恢复
  5. linux 文件按时间 函数,[Linux文件属性]使用utime函数操作文件的时间参数
  6. php 自带缓存,封装ThinkPhP自带的缓存机制
  7. python break跳出外层_失去循环标记的Python,我这样实现跳出外层循环
  8. python中什么是数据驱动_Python数据驱动DDT的应用
  9. linux内存管理的主要概念是虚拟内存,你知道linux内存管理基础及方法?
  10. 将结构体写入文件_将COCO检测结果写入json文件