队列和栈的判空都可以用empty

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. string oper,stru;
  4. int T,M,num;
  5. int main()
  6. {
  7. cin>>T;
  8. while (T--) {
  9. cin>>M>>stru;
  10. if (stru=="FIFO") {
  11. queue<int>q;
  12. for (int i=0;i<M;i++) {
  13. cin>>oper;
  14. if (oper=="IN") {
  15. cin>>num;
  16. q.push(num);
  17. }
  18. else {
  19. if (!q.empty()) {
  20. cout<<q.front()<<endl;
  21. q.pop();
  22. }
  23. else {
  24. cout<<"None"<<endl;
  25. }
  26. }
  27. }
  28. }
  29. else {
  30. stack<int>s;
  31. for (int i=0;i<M;i++) {
  32. cin>>oper;
  33. if (oper=="IN") {
  34. cin>>num;
  35. s.push(num);
  36. }
  37. else {
  38. if (!s.empty()) {
  39. cout<<s.top()<<endl;
  40. s.pop();
  41. }
  42. else {
  43. cout<<"None"<<endl;
  44. }
  45. }
  46. }
  47. }
  48. }
  49. return 0;
  50. }

HDU-1702-ACboy needs your help again!(Stack)的更多相关文章

  1. hdu 1702 ACboy needs your help again!

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1702 ACboy needs your help again! Description ACboy w ...

  2. HDU - 1702 ACboy needs your help again!(栈和队列)

    Description ACboy was kidnapped!! he miss his mother very much and is very scare now.You can't image ...

  3. HDU 1712 ACboy needs your help(包背包)

    HDU 1712 ACboy needs your help(包背包) pid=1712">http://acm.hdu.edu.cn/showproblem.php? pid=171 ...

  4. HDU 1712 ACboy needs your help (分组背包模版题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...

  5. hdu 1712 ACboy needs your help

    ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. hdu 1712 ACboy needs your help 分组背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem ...

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

  8. HDU 1712 ACboy needs your help 典型的分组背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 ACboy needs your help Time Limit: 1000/1000 MS ( ...

  9. HDU 1712 ACboy needs your help(分组背包入门题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1712 题意: 有个人学习n门课程,a[i][j]表示用j分钟学习第i门课程所能获得的价值,背包容量为一共有m时间 ...

  10. queue的使用-Hdu 1702

    ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

随机推荐

  1. php中普通类 接口类 抽象类 浅谈

    一.普通类 1.关键词:class  类名,继承关键字extends 2.继承:只能实现单继承, 3.多态:子类继承可以实现多种功能 4.封装:类有权限机制,私有的只能自己用,受保护的可以被继承,子类 ...

  2. energy/heating data source

    HeatManDataLake 1. schema: hfors tables ambient_temperature_emd record the ambient temperature hourl ...

  3. Vue开发重点基础知识

    1.Vuejs组件 vuejs构建组件使用 Vue.component('componentName',{ /*component*/ }): 这里注意一点,组件要先注册再使用,也就是说: Vue.c ...

  4. 初探selenium3原理

    从一个启动浏览器并打开百度网页的代码开始 from selenium import webdriver driver = webdriver.chrome() driver.get('https:// ...

  5. util之Map

    1.定义 Map<String, Integer> map = new HashMap<String,Integer>(); 2.判断map中是否存在某个键的值: if(map ...

  6. [USACO13JAN]Cow Lineup

    Description Luogu3069 USACO Solution 由于两个点之间最多可以有\(k+1\)种牛,而牛的种数是单调的.所以可以用尺取法(区间伸缩法),每次右移右端点后,让左端点不断 ...

  7. python+selenium:浏览器webdriver操作(0)

    1.浏览器最大化 启动的浏览器不是全屏的,这样不会影响脚本的执行,但是有时候会影响我们“观看”脚本的执行. #coding=utf-8 from selenium import webdriver i ...

  8. SpringBoot图文教程4—SpringBoot 实现文件上传下载

    有天上飞的概念,就要有落地的实现 概念+代码实现是本文的特点,教程将涵盖完整的图文教程,代码案例 文章结尾配套自测面试题,学完技术自我测试更扎实 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例 ...

  9. [Java] 多线程基础详细总结,附加详细实例

    详细代码在文章底部 目录 基础概念 进程与线程 单线程与多线程 实现线程的4中方式 thread.start()和runnable.run()的区别 Thread和Runnable的异同 线程的基本操 ...

  10. IntelliJ IDEA 2017.3尚硅谷-----修改类头的文档注释信息

    /** @author shkstart @create ${YEAR}-${MONTH}-${DAY} ${TIME} */ ${PACKAGE_NAME} - the name of the ta ...