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. opencv中的图像区域复制

    openCV作为已经成熟的开源库,很多操作它都已经有了高效,使用方便的方法.我的应用场景是这样的,从一张大图片中抠出一小部分,然后处理这一小部分后再放到大图像中.对于抠出来可以这样实现: Rect r ...

  2. socket.setNoDelay([noDelay]) 用的是Nagle算法

    Nagle算法是以他的发明人John Nagle的名字命名的,它用于自动连接许多的小缓冲器消息:这一过程(称为nagling)通过减少必须发送包的个数来增加网络软件系统的效率.Nagle算法于1984 ...

  3. 关于SQL SERVER 2008 R2发布订阅功能

    实现功能:主服务器维护数据的变更,从服务器需要时同步主服务器的数据. 配置:主从服务器均为SQL SERVER 2008 R2. 实现方法: 预备: 1.主从服务器需建立同一账户名及密码的账户(当时我 ...

  4. NOI十连测 第四测 T1

    思路:首先每个蚂蚁移速相同,而且碰到就转头,这其实等价于擦肩而过! 看到2n个数互不相同就觉得方便多了:枚举每个数字往左或者往右作为最慢,然后考虑其他蚂蚁有多少种走路方向. (1),走的距离大于m/2 ...

  5. Qt直接使用OpenSSL里的函数

    简述 OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法.常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用. 简述 下载安装 使用 更多参考 下载安装 ...

  6. 狗屎的asp.net core 果然发生了重大的变更

    狗屎的asp.net core  果然发生了重大的变更 ....仔细看官方的文档,想骂娘....你发布版本的时候,能不能先想好先设计好再发布?朝三暮四...大撒笔....你老这样变来变去,谁还敢碰你啊 ...

  7. 关于MySql链接url参数的设置

    jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/database?useUnicode=t ...

  8. perl HTML::TreeBuilder::XPath

    HTML::TreeBuilder::XPath 添加XPath 支持HTML::TreeBuilder use HTML::TreeBuilder::XPath;   my $tree= HTML: ...

  9. UESTC_魔法少女小蟹 CDOJ 710

    小蟹是一名魔法少女,能熟练的施放很多魔法. 有一天魔法学院上课的时候出现了这样一道题,给一个6位数,让大家用自己的魔法,把这个6位数变成另一个给定的6位数. 小蟹翻了下魔法书,发现她有以下6种魔法: ...

  10. Pascal's Triangle II 解答

    Question Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...