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

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
  1. #include<iostream>
  2. #include<string.h>
  3. #include<queue>
  4. #include<stack>
  5. using namespace std;
  6. queue<int>a;
  7. stack<int>b;
  8. int main()
  9. {
  10. int n,t,x;
  11. char str[],s[];
  12. cin>>n;
  13. while(n--)
  14. {
  15. cin>>t>>str;
  16. if(strcmp(str,"FIFO")==)
  17. {
  18. for(int i=;i<t;i++)
  19. {
  20. cin>>s;
  21. if(strcmp(s,"IN")==)
  22. {
  23. cin>>x;
  24. a.push(x);
  25. }
  26. else
  27. {
  28. if(a.empty())
  29. cout<<"None"<<endl;
  30. else
  31. {
  32. cout<<a.front()<<endl;
  33. a.pop();
  34. }
  35. }
  36. }
  37. while(!a.empty())
  38. a.pop();
  39. }
  40. else
  41. {
  42. for(int i=;i<t;i++)
  43. {
  44. cin>>s;
  45. if(strcmp(s,"IN")==)
  46. {
  47. cin>>x;
  48. b.push(x);
  49. }
  50. else
  51. {
  52. if(b.empty())
  53. cout<<"None"<<endl;
  54. else
  55. {
  56. cout<<b.top()<<endl;
  57. b.pop();
  58. }
  59. }
  60. }
  61. while(!b.empty())
  62. b.pop();
  63. }
  64. }
  65.  
  66. return ;
  67. }

hdu-1702-栈和队列的更多相关文章

  1. hdu 1702 栈和队列的简单应用

    #include<stdio.h> #include<string.h> #include<queue> #include<stack> using n ...

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

  3. 学习javascript数据结构(一)——栈和队列

    前言 只要你不计较得失,人生还有什么不能想法子克服的. 原文地址:学习javascript数据结构(一)--栈和队列 博主博客地址:Damonare的个人博客 几乎所有的编程语言都原生支持数组类型,因 ...

  4. [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)

    再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...

  5. 剑指Offer面试题:6.用两个栈实现队列

    一.题目:用两个栈实现队列 题目:用两个栈实现一个队列.队列的声明如下,请实现它的两个函数appendTail和deleteHead,分别完成在队列尾部插入结点和在队列头部删除结点的功能. 原文是使用 ...

  6. C实现栈和队列

    这两天再学习了数据结构的栈和队列,思想很简单,可能是学习PHP那会没有直接使用栈和队列,写的太少,所以用具体代码实现的时候出现了各种错误,感觉还是C语言功底不行.栈和队列不论在面试中还是笔试中都很重要 ...

  7. JavaScript数组模拟栈和队列

    *栈和队列:js中没有真正的栈和队列的类型              一切都是用数组对象模拟的 栈:只能从一端进出的数组,另一端封闭       FILO   何时使用:今后只要仅希望数组只能从一端进 ...

  8. 用JS描述的数据结构及算法表示——栈和队列(基础版)

    前言:找了上课时数据结构的教程来看,但是用的语言是c++,所以具体实现在网上搜大神的博客来看,我看到的大神们的博客都写得特别好,不止讲了最基本的思想和算法实现,更多的是侧重于实例运用,一边看一边在心里 ...

  9. JavaScript中的算法之美——栈、队列、表

    序 最近花了比较多的时间来学习前端的知识,在这个期间也看到了很多的优秀的文章,其中Aaron可能在这个算法方面算是我的启蒙,在此衷心感谢Aaron的付出和奉献,同时自己也会坚定的走前人这种无私奉献的分 ...

  10. Java数据结构和算法之栈与队列

    二.栈与队列 1.栈的定义 栈(Stack)是限制仅在表的一端进行插入和删除运算的线性表. (1)通常称插入.删除的这一端为栈顶(Top),另一端称为栈底(Bottom). (2)当表中没有元素时称为 ...

随机推荐

  1. xgboost 并行调参

    Parallelism When Cross Validating XGBoost Models This raises the question as to how cross validation ...

  2. Monkey压力测试Android常见的错误类型及黑白名单的使用方法

    Android常见的错误类型有两种 1.ANR类型 1)在5秒内没有响应输入的事件(例如,按键按下,屏幕触摸) 2)BroadcastReceiver在10秒内没有执行完毕 2.Crash类型 1)异 ...

  3. HttpServletResponse函數

    一.負責向客戶端發送數據的方法 1.ServletOutStream getOutputStream() 获得一个Servlet字节流输出数据 案例: response.setHeader(" ...

  4. 解决在cmder中bash(WSL)上下箭头不能使用问题

    有三种解决方式,第一种方式最简单实用 安装新版本wslbridge 这个解决方法最简单,最实用,下载第三方wslbridge,安装即可使用. 这时再进入cmder,运行bash.exe,可以发现上下左 ...

  5. 正确处理类的复合关系------新标准c++程序设计

    假设要编写一个小区养狗管理程序,该程序需要一个“主人”类,还需要一个“狗”类.狗是有主人的,主人也有狗.假定狗只有一个主人,但一个主人可以有最多10条狗.该如何处理“主人”类和“狗”类的关系呢?下面是 ...

  6. C# 密封(2)

    上一章节说到 sealed  作用于类,那么sealed 作用到方法和成员上面该如何呢. 在C# 中 Sealed作用于方法必须是重写之后的方法.也就是override+sealed.在之后别的类在继 ...

  7. 初学python - 零碎的知识点

    * 标识符命名规则 数字,字母,下划线组成,数字不能开头区分大小写 * 注释 单行:#:多行:‘ ‘ ‘ ,“”“: * 进制标识 b:二进制 o:八进制 d:十进制x:十六进制 转换:format( ...

  8. SKU:唯一标识填什么

    策略 随意填写 只要别和别人重复就好 ,不过重复你也创建不了. 最好填与APP信息相关的,比如直接填写bundle ID 上去...跟套装ID保持一致. 你新建应用的时候都还没有APP ID 你怎么填 ...

  9. kali linux之手动漏洞挖掘二

    漏洞挖掘原则/宗旨----所有变量,所有头(cookie中的变量),逐个变量删除 身份认证 常用若口令/基于字典的密码爆破/锁定帐号 信息收集(手机号,身份证,住址信息等等) 密码嗅探 会话sessi ...

  10. C#委托笔记

    参考: 第一篇:http://www.tracefact.net/tech/009.html 第二篇:http://www.tracefact.net/tech/029.html 1.委托相当于一种参 ...