Hdu 1702 ACboy needs your help again!
来源:互联网 发布:租房网站推荐 知乎 编辑:程序博客网 时间:2024/06/01 19:54
ACboy needs your help again!
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7852 Accepted Submission(s): 3958
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.
44 FIFOIN 1IN 2OUTOUT4 FILOIN 1IN 2OUTOUT5 FIFOIN 1IN 2OUTOUTOUT5 FILOIN 1IN 2OUTIN 3OUT
122112None23
#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <stack>
using namespace std;
void que_ex(int n)
{
queue<int> Q;
char s[10];
int a;
while(n--){
scanf("%s",s);
if(!strcmp(s,"IN")){
scanf("%d",&a);
Q.push(a);
}
else if(!strcmp(s,"OUT")){
if(Q.empty())
printf("None\n");
else{
printf("%d\n",Q.front());
Q.pop();
}
}
}
}
void sta_ex(int n)
{
stack<int> S;
char s[10];
int a;
while(n--){
scanf("%s",s);
if(!strcmp(s,"IN")){
scanf("%d",&a);
S.push(a);
}
else if(!strcmp(s,"OUT")){
if(S.empty())
printf("None\n");
else{
printf("%d\n",S.top());
S.pop();
}
}
}
}
int main()
{
int n;
while(~scanf("%d",&n)){
while(n--){
int m;
char str[100];
scanf("%d%s",&m,str);
if(!strcmp(str,"FIFO"))
que_ex(m);
else if(!strcmp(str,"FILO"))
sta_ex(m);
else
printf("error\n");
}
}
return 0;
}
- HDU 1702 ACboy needs your help again!
- HDU 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- HDU-ACboy needs your help again!-1702
- hdu 1702 ACboy needs your help again
- HDU 1702 ACboy needs your help again!
- HDU-1702-ACboy needs your help again!
- HDU 1702 ACboy needs your help again!
- hdu---1702ACboy needs your help again!
- HDU - 1702 ACboy needs your help again!
- HDU 1702 ACboy needs your help again!
- HDU 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- HDU - 1702 ACboy needs your help again!
- 样式表,脚本阻塞
- java操作Excel
- linux驱动学习(八) i2c驱动架构(史上最全) davinc dm368 i2c驱动分析
- struts2获取作用域对象---【小白系列】0基础到熟练应用struts2框架(三)
- 视频质量测试常见编解码表,各种视频测试知识列表
- Hdu 1702 ACboy needs your help again!
- 按返回键实现home键的效果
- Hibernate中的Entity类之间的继承关系之一MappedSuperclass
- 如何实现在Windows下编写的代码,直接在Linux下编译
- Material Design UI Widgets —— ActivityOptions转场动画
- ecache控制标签放在service还是dao层
- SQL查询速度
- 记录:最近所做的小实例
- CentOS7:常见问题