zoukankan      html  css  js  c++  java
  • ACboy needs your help again!

    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)
     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
    ");
    29                         continue;
    30                     }
    31                     printf("%d
    ",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
    ");
    54                         continue;
    55                     }
    56                     i--;
    57                     printf("%d
    ",b[i]);
    58                 }
    59             }
    60         }
    61     }
    62     return 0;
    63 }
    View Code
    转载请备注:
    **************************************
    * 作者: Wurq
    * 博客: https://www.cnblogs.com/Wurq/
    * Gitee: https://gitee.com/wurq
    **************************************
  • 相关阅读:
    java中的线程是如何工作的。
    springcloud 负载均衡之 ribbon。
    eureka 集群的实现方式?
    eureka的简单介绍,eureka单节点版的实现?eureka的自我保护?eureka的AP性,和CP性?
    docker常用命令、镜像命令、容器命令、数据卷,使用dockerFile创建镜像,dockefile的语法规则。
    关于自动化测试框架的思想和考虑
    Web应用程序压力测试步骤
    自动化测试工具的选择
    软件测试用例的认识误区
    如何评估软件产品的质量?
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750316.html
Copyright © 2011-2022 走看看