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 ( ...
随机推荐
- struts2中的constant常量配置
struts2中的constant配置详解 本文主要讲解一下struts2中的constant常量配置,内容主要来自于互联网的整理.<?xml version="1.0" e ...
- php header的使用
// okheader('HTTP/1.1 200 OK'); //设置一个404头:header('HTTP/1.1 404 Not Found'); //设置地址被永久的重定向header('HT ...
- 巨杉Tech | 十分钟快速搭建 Wordpress 博客系统
介绍 很多互联网应用程序开发人员第一个接触到的网站项目就是博客系统.而全球使用最广的Wordpress常常被用户用来快速搭建个人博客网站.默认情况下,Wordpress一般在后台使用MySQL关系型数 ...
- linux修改主机名(hostname)
修改/etc/sysconfig/network文件并重启
- 如何在Word中批量选中特定文本
如何在Word中批量选中特定文本 举个例子,我们对如下文本进行操作,将文本中所有的“1111111”标红,所有的“2222222”标绿,所有的“3333333”标蓝 在Word中找到“查找”下的“高级 ...
- 线性混合+ROI
相关代码: #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namesp ...
- Game of Credit Cards
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- 每天进步一点点------Xilinx IP 内核
ISE 设计套件 11.1 版本中提供了众多全新的 IP 内核.数学函数:Multiply Adder v2.0 —— 执行两个操作数的乘法,并采用 XtremeDSP™ 解决方案切片将完全精确的乘积 ...
- 使用表单对象时,报错 form is undefine
先看例子 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...
- Codeforces 1204D2. Kirk and a Binary String (hard version) (dp思路)
题目链接:http://codeforces.com/contest/1204/problem/D2 题目是给定一个01字符串,让你尽可能多地改变1变为0,但是要保证新的字符串,对任意的L,R使得Sl ...