• hdu 1702 ACboy needs your help again!


    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=1702

    ACboy needs your help again!

    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.

    SampleInput

    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

    SampleOutput

    1
    2
    2
    1
    1
    2
    None
    2
    3

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<vector>
     7 #include<queue>
     8 #include<stack>
     9 #include<map>
    10 #include<set>
    11 using std::cin;
    12 using std::cout;
    13 using std::endl;
    14 using std::find;
    15 using std::sort;
    16 using std::set;
    17 using std::map;
    18 using std::pair;
    19 using std::stack;
    20 using std::queue;
    21 using std::vector;
    22 #define sz(c) (int)(c).size()
    23 #define all(c) (c).begin(), (c).end()
    24 #define iter(c) decltype((c).begin())
    25 #define cls(arr,val) memset(arr,val,sizeof(arr))
    26 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    27 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
    28 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
    29 #define pb(e) push_back(e)
    30 #define mp(a, b) make_pair(a, b)
    31 const int Max_N = 100010;
    32 typedef unsigned long long ull;
    33 queue<int> que; stack<int> stk;
    34 int main() {
    35 #ifdef LOCAL
    36     freopen("in.txt", "r", stdin);
    37     freopen("out.txt", "w+", stdout);
    38 #endif
    39     int n, v, t;
    40     char buf[10];
    41     scanf("%d", &t);
    42     while (t--) {
    43         scanf("%d %s", &n, buf);
    44         if ('F' == buf[2]) {
    45             rep(i, n) {
    46                 scanf("%s", buf);
    47                 if ('I' == buf[0]) scanf("%d", &v), que.push(v);
    48                 else {
    49                     if (que.empty()) { puts("None"); continue; }
    50                     printf("%d
    ", que.front()), que.pop();
    51                 }
    52             }
    53         } else {
    54             rep(i, n) {
    55                 scanf("%s", buf);
    56                 if ('I' == buf[0]) scanf("%d", &v), stk.push(v);
    57                 else {
    58                     if (stk.empty()) { puts("None"); continue; }
    59                     printf("%d
    ", stk.top()), stk.pop();
    60                 }
    61             }
    62         }
    63         while (!stk.empty()) stk.pop(); while (!que.empty()) que.pop();
    64     }
    65     return 0;
    66 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    打开fiddler之后,python写的爬虫无法正常运行
    Fiddler抓包https失败踩坑
    python 报错 name is not defined
    HttpWebRequest爬虫问题汇总
    Navicat Premium 16 for Mac 最新版
    CentOS升级polkit版本,解决 Linux Polkit 存在权限提升的漏洞 (CVE20214034)
    Nginx Proxy Manager
    docker tar.gz
    C# HttpClientHandle
    nginx joplin
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4584070.html
Copyright © 2020-2023  润新知