HDU1702:ACboy needs your help again!
ACboy needs your help again!
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10095 Accepted Submission(s): 5066
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!
The first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.
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
2
2
1
1
2
None
2
3
每组数据结束后,记得把队列/栈清空,否则会wa
empty()用来检查队列/栈是否为空,为空返回true
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int main()
{
int t,n,m;
char ch[50],sh[50];
cin>>t;
queue<int>que;
stack<int>s;
while(t--)
{
while(!s.empty()) s.pop();
while(!que.empty()) que.pop();//直到队列/栈空的时候,停止操作
cin>>n>>ch;
if(strcmp(ch,"FIFO")==0)
{
for(int i=0;i<n;i++)
{
cin>>sh;
if(strcmp(sh,"IN")==0)
{
cin>>m;
que.push(m);
}
if(strcmp(sh,"OUT")==0)
{
if(que.size()>0)
{
cout<<que.front()<<endl;
que.pop();
}
else cout<<"None\n";
}
}
}
if(strcmp(ch,"FILO")==0)
{
for(int i=0;i<n;i++)
{
cin>>sh;
if(strcmp(sh,"IN")==0)
{
cin>>m;
s.push(m);
}
if(strcmp(sh,"OUT")==0)
{
if(s.size()>0)
{
cout<<s.top()<<endl;
s.pop();
}
else cout<<"None\n";
}
}
}
}
return 0;
}
HDU1702:ACboy needs your help again!的更多相关文章
- HDU1712:ACboy needs your help(分组背包)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1712 解释看这里:http://www.cnblogs.com/zhangmingcheng/p/3940 ...
- 分组背包 例题:hdu 1712 ACboy needs your help
分组背包需求 有N件物品,告诉你这N件物品的重量以及价值,将这些物品划分为K组,每组中的物品互相冲突,最多选一件,求解将哪些物品装入背包可使这些物品的费用综合不超过背包的容量,且价值总和最大. 解题模 ...
- (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 ...
- STL专题
一.algorithm 1.sort 问题1:给你n个整数,请按从大到小的顺序输出其中前m大的数. Input:每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二 ...
- stl 题目总结
stl 题目总结 一.圆桌问题 1 .问题: 圆桌上围坐着2n个人.其中n个人是好人,另外n个人是坏人.如果从第一个人开始数数,数到第m个人,则立即处死该人:然后从被处死的人之后开始数数,再将数到的第 ...
- java web 开发三剑客 -------电子书
Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...
- 所有selenium相关的库
通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...
- ACboy needs your help again!--hdu1702
ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu1702 ACboy needs your help again!(栈处理)
ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- Codeforces 140D - New Year Contest
140D - New Year Contest 思路:贪心+排序.罚时与时间成正比,因为在0点前做完的题都可以在0点提交.从时间短的开始做最优. 代码: #include<bits/stdc++ ...
- jsp / get 中文乱码问题
POST 方式下的解决方式还算简单,因为POST 方式下提交的数据都是以二进制的方式附加在http请求的body部分发送,只需要在后台指定编码格式就足矣解决. GET 方式下会将参数直接附加到url ...
- 探索gff/gtf格式
参考: GFF格式说明 Generic Feature Format Version 3 (GFF3) 先下载一个 gtf 文件浏览一下 1 havana gene 11869 14409 . + . ...
- python下编译py成pyc和pyo和pyd
https://www.cnblogs.com/dkblog/archive/2009/04/16/1980757.html
- English trip V1 - 1.How Do You Feel Now? Teacher:Lamb Key:形容词(Adjectives)
In this lesson you will learn to describe people, things, and feelings.在本课中,您将学习如何描述人,事和感受. STARTER ...
- English trip -- VC(情景课)10 A Get ready 预备课
Words dance 跳舞 exercise 运动:锻炼 fish 鱼 play basketball 打篮球 play cards 玩牌 swim 游泳 decorations 装饰品 ...
- 【模板/经典题型】带有直线限制的NE Latice Path计数
平移一下,变成不能接触y=x+1. 注意下面的操作(重点) 做点p=(n,m)关于这条直线的对称点q=(m-1,n+1). ans=f(p)-f(q). 其中f(x)为从(0,0)到点x的方案数.
- tomcat8w.exe 运行 提示 指定的服务未安装 unable to open the service 'tomcat8'
新下载的Tomcat8 解压版,解压缩完成后,双击tomcat8.exe出现个DOS样子的窗口一闪而过消失了,tomcat也没有启动成功.双击tomcat8w.exe 弹出个错误对话框,说“指定的服务 ...
- 转化为json方式函数
1,我的数据格式是: {"message":"","code":0,"data":[{"Order" ...
- STL_string
将string对象利用c风格的形式输出函数: c_str() 栗子: string s; printf("%s\n",s.c_str());