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

Problem Description
ACboy was kidnapped!!
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!
 
Input
The input contains multiple test cases.
The first line has one integer,represent the number oftest cases.
And the input of each subproblem are described above.
 
Output
For each command "OUT", you should output a integer depend on the word is "FIFO" or "FILO", or a word "None" if you don't have any integer.
 
Sample Input
4
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
3
 
Sample Output
1
2
2
1
1
2
None
2
3
 
这个题大意就是:FIFO代表是先输入的数先输出,FILO代表的是先输入的数后输出。没有数据就输出None!
很容易想到用栈和队列来解决问题。
 
 
 
 #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的更多相关文章

  1. hdu1702 ACboy needs your help again!(栈处理)

    ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  2. HDU1702:ACboy needs your help again!

    ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  3. hdu1702 ACboy needs your help again![简单STL 栈 队列]

    目录 题目地址 题干 代码和解释 参考 题目地址 hdu1702 题干 代码和解释 本题很简单,只要掌握STL stack和STL vector的语法即可作答.记录本题是为了记录STL vector的 ...

  4. hdu 1702 ACboy needs your help again!

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1702 ACboy needs your help again! Description ACboy w ...

  5. (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 ...

  6. hdu 1712 ACboy needs your help

    ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. hdu 1712 ACboy needs your help 分组背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem ...

  8. 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 ( ...

  9. HDU 1712 ACboy needs your help 典型的分组背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 ACboy needs your help Time Limit: 1000/1000 MS ( ...

随机推荐

  1. css布局学习笔记之box-sizing

    当你设置了元素的宽度,实际展现的元素却能够超出你的设置:因为元素的边框和内边距会撑开元素. .div{ width: 500px; margin: 20px auto; padding: 50px; ...

  2. 【转】Apache配置中ProxyPassReverse指令的含义

    此文章来源:http://blog.csdn.net/yl_wh/article/details/8697501 apache中的mod_proxy模块主要作用就是进行url的转发,即具有代理的功能. ...

  3. static的用法解析

    PHP中static变量的使用范围要更广一些,我们不仅可以在类,方法或变量前面添加static修饰符,我们甚至还能给函数内部变量添加static关键字.添加了static修饰符的变量即使在该函数执行完 ...

  4. opencv + numpy for python

    OpenCV的全称是:Open Source Computer Vision Library.OpenCV是一个基于(开源)发行的跨平台计算机视觉库,可以运行在Linux.Windows和Mac OS ...

  5. information_schema.columns 学习

    每一个表中的每一列都会在information_schema.columns表中对应一行 1.informaiton_schema.columns 常用列: 1.table_catalog :不管是t ...

  6. 自己动手写PHP MVC框架

    自己动手写PHP MVC框架 来自:yuansir-web.com / yuansir@live.cn 代码下载: https://github.com/yuansir/tiny-php-framew ...

  7. 开心菜鸟系列学习笔记------javascript(4)

    一.全局上下文中的变量对象:        1)全局对象(Global object) 是在进入任何执行上下文之前就已经创建了的对象:这个对象只存在一份,它的属性在程序中任何地方都可以访问,全局对象的 ...

  8. unzip解压中文文件名乱码

    由于中文的Windows使用的是GBK编码,而Linux默认使用UTF-8编码的,如果在Windows打包带中文文件的zip包,则这个zip包在Linux下面使用默认的归档管理器打开这个zip包的时候 ...

  9. HTML实体符号

    http://www.php100.com/html/program/html/2013/0903/1052.html

  10. 使用XAML在WPF项目中承载ArcGIS Engine地图控件开发

    原文 http://blog.csdn.net/flexmapserver/article/details/5868882 用Windows Form进行ArcGIS Engine二次开发时常见的形式 ...