• refresh停车场


    题目描述

     refresh最近发了一笔横财,开了一家停车场。由于土地有限,停车场内停车数量有限,但是要求进停车场的车辆过多。当停车场满时,要进入的车辆会进入便道等待,最先进入便道的车辆会优先
    进入停车场,而且停车场的结构要求只出去的车辆必须是停车场中最后进去的车辆。现告诉你停车场容量N以及命令数M,以及一些命令(Add num 表示车牌号为num的车辆要进入停车场或便道,
    Del 表示停车场中出去了一辆车,Out 表示便道最前面的车辆不再等待,放弃进入停车场)。假设便道内的车辆不超过1000000.

    输入

     首先输入N和M(0< n,m <200000),接下来输入M条命令。

    输出

     输入结束后,如果出现停车场内无车辆而出现Del或者便道内无车辆而出现Out,则输出Error,否则输出停车场内的车辆,最后进入的最先输出,无车辆不输出。

    示例输入

    2 6
    Add 18353364208
    Add 18353365550
    Add 18353365558
    Add 18353365559
    Del
    Out

    示例输出

    18353365558
    18353364208
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<string>
     4 #include<stack>
     5 #include<iostream>
     6 #include<queue>
     7 using namespace std;
     8 int main()
     9 {
    10     int n,m,t;
    11     char str[20];
    12     string s;
    13     while(~scanf("%d %d",&n,&m))
    14     {stack<string>st;
    15     queue<string>q;
    16     t=0;
    17     for(int i=0;i<m;i++)
    18     {
    19         scanf("%s",str);
    20         if(strcmp(str,"Add")==0)
    21         {
    22             cin>>s;
    23             if(st.size()==n)
    24             q.push(s);
    25             else
    26             st.push(s);
    27         }
    28         else if(strcmp(str,"Del")==0)
    29         {
    30             if(st.empty())
    31             t=1;
    32             else
    33             {
    34                 st.pop();
    35                 if(!q.empty())
    36                 {
    37                     st.push(q.front());
    38                     q.pop();
    39                 }
    40             }
    41         }
    42         else if(strcmp(str,"Out")==0)
    43         {
    44             if(q.empty())
    45             t=1;
    46             else
    47             q.pop();
    48         }
    49     }
    50     if(t==1)
    51     printf("Error\n");
    52     else
    53     {
    54         while(!st.empty())
    55         {
    56             cout<<st.top()<<endl;
    57             st.pop();
    58         }
    59     }
    60     }
    61     return 0;
    62 }
    View Code

    芳姐的粉丝。。。

  • 相关阅读:
    Visual C# 2008+SQL Server 2005 数据库与网络开发14.1.2 WPF的组成
    Visual C# 2008+SQL Server 2005 数据库与网络开发13.1.3 简单记事本程序菜单设计
    Visual C# 2008+SQL Server 2005 数据库与网络开发13.1.1 菜单创建
    Feathers TextInput使KeyboardEvent失效
    UILabel 多行显示
    突破flash player的睡眠模式
    突破flash player睡眠模式 后续
    缩放UIImage
    IT菜鸟报到!
    用VMware装了Ubuntu后,安装VMware Tools
  • 原文地址:https://www.cnblogs.com/sdutmyj/p/3225100.html
Copyright © 2020-2023  润新知