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
    **************************************
  • 相关阅读:
    Kruskal重构树学习笔记
    亚洲和欧洲的分界线是谁划分的?
    代码目录 (App_Code 目录)及namespace的理解
    Events解惑——来自MSDN
    HttpContext.Current.Response和Response有什么区别?
    Ramdisk 内存盘的使用
    MVC模式 介绍
    关于Windows Workflow Foundation 调试时的经验小解(不断添加)
    关于类成员变量的声明和实例化的时机
    软件名称备份
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750316.html
Copyright © 2011-2022 走看看