ACboy needs your help again!--hdu1702
ACboy needs your help again!
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4429 Accepted Submission(s): 2260
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.
#include<stdio.h>
#include<string.h>
#include<stack>
#include<queue>
using namespace std;
char s1[],s2[];
int main()
{
int n,a,b; scanf("%d",&n);
while(n--)
{
queue<int>s;//定义一个队列
while(!s.empty())
s.pop();
stack<int>r;//定义一个栈
while(!r.empty())
r.pop();//一定要每次都要清空队列,要不然各种WA我也是醉了!
scanf("%d %s",&a,s1);
getchar();//注意吸收回车
if(strcmp(s1,"FIFO")==)
{
while(a--)
{
scanf("%s",s2);
if(strcmp(s2,"IN")==)
{
scanf("%d",&b);
getchar();
s.push(b);
}
else if(strcmp(s2,"OUT")==)
{
if(s.empty())
printf("None\n");
else
{
printf("%d\n",s.front());//输出队首元素
s.pop();
} }
}
}
else if(strcmp(s1,"FILO")==)
{
while(a--)
{
scanf("%s",s2);
if(strcmp(s2,"IN")==)
{
scanf("%d",&b);
getchar();
r.push(b);
}
else if(strcmp(s2,"OUT")==)
{
if(r.empty())
printf("None\n");
else
{
printf("%d\n",r.top());//输出栈顶元素
r.pop();
} }
}
}
}
return ;
}
ACboy needs your help again!--hdu1702的更多相关文章
- hdu1702 ACboy needs your help again!(栈处理)
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 ( ...
- hdu1702 ACboy needs your help again![简单STL 栈 队列]
目录 题目地址 题干 代码和解释 参考 题目地址 hdu1702 题干 代码和解释 本题很简单,只要掌握STL stack和STL vector的语法即可作答.记录本题是为了记录STL vector的 ...
- 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 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 ...
- 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 ( ...
随机推荐
- css布局学习笔记之box-sizing
当你设置了元素的宽度,实际展现的元素却能够超出你的设置:因为元素的边框和内边距会撑开元素. .div{ width: 500px; margin: 20px auto; padding: 50px; ...
- 【转】Apache配置中ProxyPassReverse指令的含义
此文章来源:http://blog.csdn.net/yl_wh/article/details/8697501 apache中的mod_proxy模块主要作用就是进行url的转发,即具有代理的功能. ...
- static的用法解析
PHP中static变量的使用范围要更广一些,我们不仅可以在类,方法或变量前面添加static修饰符,我们甚至还能给函数内部变量添加static关键字.添加了static修饰符的变量即使在该函数执行完 ...
- opencv + numpy for python
OpenCV的全称是:Open Source Computer Vision Library.OpenCV是一个基于(开源)发行的跨平台计算机视觉库,可以运行在Linux.Windows和Mac OS ...
- information_schema.columns 学习
每一个表中的每一列都会在information_schema.columns表中对应一行 1.informaiton_schema.columns 常用列: 1.table_catalog :不管是t ...
- 自己动手写PHP MVC框架
自己动手写PHP MVC框架 来自:yuansir-web.com / yuansir@live.cn 代码下载: https://github.com/yuansir/tiny-php-framew ...
- 开心菜鸟系列学习笔记------javascript(4)
一.全局上下文中的变量对象: 1)全局对象(Global object) 是在进入任何执行上下文之前就已经创建了的对象:这个对象只存在一份,它的属性在程序中任何地方都可以访问,全局对象的 ...
- unzip解压中文文件名乱码
由于中文的Windows使用的是GBK编码,而Linux默认使用UTF-8编码的,如果在Windows打包带中文文件的zip包,则这个zip包在Linux下面使用默认的归档管理器打开这个zip包的时候 ...
- HTML实体符号
http://www.php100.com/html/program/html/2013/0903/1052.html
- 使用XAML在WPF项目中承载ArcGIS Engine地图控件开发
原文 http://blog.csdn.net/flexmapserver/article/details/5868882 用Windows Form进行ArcGIS Engine二次开发时常见的形式 ...