ACboy needs your help again!(1702)
2015-07-18 13:58
495 查看
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
Sample Output
1
2
2
1
1
2
None
2
3
注意:保存与输出的顺序即可。
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
Sample Output
1
2
2
1
1
2
None
2
3
注意:保存与输出的顺序即可。
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <ctype.h> int main() { int N,n,i,j; char rule[10]; char str[10]; int flag,biao; int s[1000]; while(scanf("%d",&N)!=EOF) { while(N--) { //memset(s,2147483647,sizeof(s)); for(i=0;i<1000;i++) s[i]=2147483647; scanf("%d",&n); scanf("%s",rule); if(strcmp(rule,"FIFO")==0) flag=1; else flag=0; for(i=0;i<n;i++) { biao=0; scanf("%s",str); if(str[0]=='I') { scanf("%d",&s[i]); } else { if(flag==1) { for(j=0;j<=i;j++) { if(s[j]!=2147483647) { printf("%d\n",s[j]); biao=1; s[j]=2147483647; break; } } } else { for(j=i-1;j>=0;j--) { if(s[j]!=2147483647) { printf("%d\n",s[j]); biao=1; s[j]=2147483647; break; } } } if(biao==0) printf("None\n"); } } } } return 0; }
相关文章推荐
- Linux C函数参考手册(PDF版)
- Lua教程(十七):C API简介
- C#实现打造气泡屏幕保护效果
- C/C++数据对齐详细解析
- C 语言基础教程(我的C之旅开始了)[三]
- C++中的extern “C”用法详解
- C 语言基础教程(我的C之旅开始了)[七]
- C字符串操作函数实现方法小结
- C/C++ 宏详细解析
- C/C++实现对STORM运行信息查看及控制的方法
- 用C#生成不重复的随机数的代码
- 在c和c++中实现函数回调
- 浅析C/C++中被人误解的SIZEOF
- C 语言基础教程(我的C之旅开始了)[六]
- C/C++实现的游戏角色名称名字随机生成代码
- C/C++函数调用的几种方式总结
- c/c++中变量的声明和定义深入解析
- 浅析c与c++中struct的区别
- 深入详解C编写Windows服务程序的五个步骤