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

#include <bits/stdc++.h>
using namespace std; string oper,stru;
int T,M,num; int main()
{
cin>>T;
while (T--) {
cin>>M>>stru;
if (stru=="FIFO") {
queue<int>q;
for (int i=0;i<M;i++) {
cin>>oper;
if (oper=="IN") {
cin>>num;
q.push(num);
}
else {
if (!q.empty()) {
cout<<q.front()<<endl;
q.pop();
}
else {
cout<<"None"<<endl;
}
}
}
}
else {
stack<int>s;
for (int i=0;i<M;i++) {
cin>>oper;
if (oper=="IN") {
cin>>num;
s.push(num);
}
else {
if (!s.empty()) {
cout<<s.top()<<endl;
s.pop();
}
else {
cout<<"None"<<endl;
}
}
}
}
}
return 0;
}

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. Computer Abstractions

    计算机系统结构的概述 (MOOC:计算机系统设计) 组成: 硬件:CPU +MM(主存)+I/O(输入/输出) 软件:系统软件+应用软件 层次结构: 发展简史: 第一代:真空管  ·ENIAC ·冯诺 ...

  2. CSS遮罩层简易写法

      现在很多站点弹出框,都需要一个遮罩层.写法很多,以下是我比较喜欢的一种: .box{ position:absolute; top:0; bottom:0; left:0; right:0; ba ...

  3. IntelliJ IDEA 2017.3尚硅谷-----生成 javadoc

    Locale:输入语言类型:zh_CN Other command line arguments:-encoding UTF-8 -charset UTF-8

  4. JSON.toJSONString(Object object,SerializerFeature...features)详解

    D package myProject; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; ...

  5. L1-2 倒数第N个字符串

    思路 这题就是一道进制转换,用26进制表示一个数,以及26进制下的数的加减操作. 代码 #include <bits/stdc++.h> using namespace std; int ...

  6. 初学Java时使用记事本开发出现的中文乱码问题

    如果是使用微软记事本,那就会麻烦一点,将后缀改为.txt,用记事本打开,左上方:文件→另存为→弹出的窗口的下方会出现使用的编码形式,将编码形式修改为ANSI编码,点击保存→确定替换即可,修改后将后缀改 ...

  7. 【 js 上传文件】

    上传文件 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ...

  8. 每天进步一点点------Allegro 建立封装的一般步骤

    在制作封装之前,先确定你需要的焊盘,如果库中没有,那就要自己画了,(我就是自己画的) 制作二极管1N5822 SMD,实际尺寸:480milX520mil 一.添加元件焊盘 1 启动Allegro P ...

  9. Codeforces Round #567 (Div. 2) A.Chunga-Changa

    原文链接:传送 #include"algorithm" #include"iostream" #include"cmath" using n ...

  10. HTML连载60-水平居中与设计一个团购界面

    一.水平居中 1.margin:0 auto在绝对定位中就失效了 2.如何让绝对定位的元素水平居中? 只需要设置绝对定位元素的left:50%:然后再设置绝对定位元素的margin-left:-元素宽 ...