码迷,mamicode.com
首页 > 其他好文 > 详细

ACboy needs your help again!

时间:2014-05-25 19:35:18      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   c   code   

ACboy needs your help again!

Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 36   Accepted Submission(s) : 29

Font: Times New Roman | Verdana | Georgia

Font Size:  

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

Sample Output

1
2
2
1
1
2
None
2
3

Source

2007省赛集训队练习赛(1)
bubuko.com,布布扣
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 
 5 int main()
 6 {
 7     int N,FIFO,FILO,b[100000],i,j,T,sign[10000],sum;
 8     scanf("%d",&N);
 9     while(N--)
10     {
11         scanf("%d%s",&T,sign);
12         if(strcmp(sign,"FIFO")==0)
13         {
14             i=0;
15             j=0;
16             while(T--)
17             {
18                 scanf("%s",sign);
19                 if(strcmp(sign,"IN")==0)
20                 {
21                     scanf("%d",&b[i]);
22                     i++;
23                 }
24                 else if(strcmp(sign,"OUT")==0)
25                 {
26                     if(i==j)
27                     {
28                         printf("None\n");
29                         continue;
30                     }
31                     printf("%d\n",b[j]);
32                     j++;
33                 }
34 
35             }
36         }
37         else if(strcmp(sign,"FILO")==0)
38         {
39             i=0;
40             j=0;
41             while(T--)
42             {
43                 scanf("%s",sign);
44                 if(strcmp(sign,"IN")==0)
45                 {
46                     scanf("%d",&b[i]);
47                     i++;
48                 }
49                 else if(strcmp(sign,"OUT")==0)
50                 {
51                     if(i==0)
52                     {
53                         printf("None\n");
54                         continue;
55                     }
56                     i--;
57                     printf("%d\n",b[i]);
58                 }
59             }
60         }
61     }
62     return 0;
63 }
View Code

 

ACboy needs your help again!,布布扣,bubuko.com

ACboy needs your help again!

标签:des   style   class   blog   c   code   

原文地址:http://www.cnblogs.com/LWF5201314614/p/3750316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!