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. css3 页面退出和进入的动画

    @-webkit-keyframes slideIn { from { -webkit-transform: translate3d(100%,0,0); transform: translate3d ...

  2. Ubuntu 安装 pecl_http

    由于开发环境需要用到pecl_http,根据网上找的教程一直没用按照成功,查看错误,pcre这里出错了,原来要安装这个libpcre3-dev,安装好这个就成功了,记下命令. $ sudo apt-g ...

  3. win7 tomcat

    前提需要有java环境 cmd 1- 下载tomcat http://tomcat.apache.org/ download Tomcat7.0 2- 配置环境变量 CATALINA_HOME C:\ ...

  4. symfony2路径问题

    1.相对路径 例:在上传文件里面,路径设置为 $path = "upload/"   此时路径指向的是web/upload/; 2.绝对路径 例:$path = "/va ...

  5. TCP连接状态图

  6. QSizePolicy可均匀调整控件的大小,还可设置比例,非常完美(每个QWidget都有这个功能)

    http://blog.csdn.net/liang19890820/article/details/51986284 它是QWidget的固有属性: http://doc.qt.io/qt-4.8/ ...

  7. android 签名被篡改(Keystore was tampered with, or password was incorrect)

    在配置自定义签名时出现了"Keystore was tampered with, or password was incorrect"错误! 参考文档发现: If necessar ...

  8. 杭电1010(dfs + 奇偶剪枝)

    题目: The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked ...

  9. 【HDU 4547 CD操作】LCA问题 Tarjan算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4547 题意:模拟DOS下的cd命令,给出n个节点的目录树以及m次查询,每个查询包含一个当前目录cur和 ...

  10. hdu 5626 Clarke and points

    Problem Description Clarke is a patient with multiple personality disorder. One day he turned into a ...