HDU-1702-ACboy needs your help again!(Stack)
队列和栈的判空都可以用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)的更多相关文章
- hdu 1702 ACboy needs your help again!
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1702 ACboy needs your help again! Description ACboy w ...
- 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 ...
- HDU 1712 ACboy needs your help(包背包)
HDU 1712 ACboy needs your help(包背包) pid=1712">http://acm.hdu.edu.cn/showproblem.php? pid=171 ...
- HDU 1712 ACboy needs your help (分组背包模版题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...
- hdu 1712 ACboy needs your help
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1712 ACboy needs your help 分组背包
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem ...
- 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 ( ...
- HDU 1712 ACboy needs your help 典型的分组背包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 ACboy needs your help Time Limit: 1000/1000 MS ( ...
- HDU 1712 ACboy needs your help(分组背包入门题)
http://acm.hdu.edu.cn/showproblem.php?pid=1712 题意: 有个人学习n门课程,a[i][j]表示用j分钟学习第i门课程所能获得的价值,背包容量为一共有m时间 ...
- queue的使用-Hdu 1702
ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- 一些docker资料汇总
安装vmtools https://blog.csdn.net/qq_37764098/article/details/95538813 挂载vm共享文件夹 https://www.cnblogs.c ...
- 题解【洛谷P1725】琪露诺
题面 典型的单调队列优化\(\text{DP}\)题. 不难想到设\(dp_i\)表示以\(i\)结尾能得到的最大冰冻指数. 这样设的转移方程也很简单:\(dp_i=\max\left\{ dp_j+ ...
- Ajax返回值一直获取不到啊
原理: 同步异步的问题 Return 位置的问题 首先同步异步改为async : false, Return 的值写在ajax外部 function submit_answer(){ ...
- NPOI _导出exl(简单应用)
1. 导出exl表格,创建表格导出到客户端 public static MemoryStream Export_Table<T>(List<T> datalist) { Mem ...
- 如何在vivado中调用ultraedit 编辑器
ISE下点击菜单Edit -> Preferences -> Editor. 在Editor选项框里选择Custom,在Command line syntax文本框里输入: {C:/Pro ...
- 三、ZigBee无线网络工具
CC2530概述 CC2530是德州仪器Ti公司用于2.4-GHz IEEE 802.15.4.ZigBee 和 RF4CE 应用的一个真正的片上系统(SoC)解决方案,是作为ZigBee无线传 感网 ...
- Jquery动态改变my97datepicker的日期形式
先要解绑触发事件: $('#start').unbind('focus'); 然后再绑定触发事件: $('#start').bind('focus',function(){WdatePicker({s ...
- Web API入参,响应规范
入参绑定 入参应该定义成实体,而不是多个参数,方便扩展.[FromBody]和[FromUrl]特性也最好加上. public ActionResult<Pet> Create([From ...
- L2-3 名人堂与代金券
题解 这题的话,每一个人都要占一个排名,即使排名并列了. 对于最后一个排名来说,即使人数超过了指定的k,也要加入. 代码 #include <bits/stdc++.h> using na ...
- AcWing 898. 数字三角形
//从上往下 #include <iostream> #include <algorithm> using namespace std; , INF = 1e9; int n; ...