• HDU--1702 ACboy needs your help again!


     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
    Output:
    1
    2
    2
    1
    1
    2
    None
    2
    3
    AC代码:
     1 #include<stdio.h>
     2 #include<stack>
     3 #include<queue>
     4 using namespace std;
     5 int main()
     6 {
     7     int n,m;
     8     char c[5];
     9     scanf("%d",&n);
    10     while(n--)
    11     {scanf("%d %s",&m,c);
    12      queue<int>q;
    13      stack<int>s;
    14      while(m--)
    15        {  if(c[2]=='F')//队列 
    16           {
    17            char d[4];
    18            int j;
    19            scanf("%s",d);
    20            if(d[0]=='I')
    21             {scanf("%d",&j);
    22              q.push(j);
    23                
    24             }
    25           else
    26             {if(q.empty()) printf("None
    ");
    27              else 
    28               {int x;
    29                x=q.front();
    30                printf("%d
    ",x);
    31                q.pop();
    32                   
    33               }
    34                
    35             }  
    36             
    37           }
    38           else        //
    39            { 
    40              char e[4];
    41              int k;
    42              scanf("%s",e);
    43              if(e[0]=='I')
    44                {scanf("%d",&k);
    45                 s.push(k);
    46                
    47                }
    48              else
    49               {if(s.empty()) printf("None
    ");
    50                else 
    51                 {int y;
    52                  y=s.top();
    53                  printf("%d
    ",y);
    54                  s.pop();
    55                   
    56                 }
    57                
    58               }  
    59             
    60             
    61            }        
    62            
    63        }
    64         
    65     }
    66     return 0;
    67 }
    
    
    
    
  • 相关阅读:
    WCF发布后的地址中域名与IP地址的问题
    asp.net判断字符串是否包含特殊字符
    silverlight中DataGrid错误:data未定义
    变电所、分区所、AT所
    Angela Aki 给十五岁的自己
    WCF绑定(Binding)
    几个不错的WCF系列课程
    WCF服务编程学习笔记之服务契约
    asp.net跳转页面的三种方法比较
    Hashtable快速查找的方法
  • 原文地址:https://www.cnblogs.com/hss-521/p/7235810.html
Copyright © 2020-2023  润新知