zoukankan      html  css  js  c++  java
  • 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>
     3 #include<string.h>
     4 #include<iostream>
     5 #include<stack>
     6 #include<queue>
     7 using namespace std;
     8 
     9 int main()
    10 {
    11     int n,m,f;
    12     char s[15];
    13     string ss;
    14     while(~scanf("%d %d",&n,&m))
    15     {
    16         stack<string>st;
    17         queue<string>que;
    18         f = 0;
    19         for(int i = 1; i <= m; i++)
    20         {
    21             scanf("%s",s);
    22             if(strcmp("Add",s) == 0)
    23             {
    24                 cin>>ss;
    25                 if(st.size() == n)
    26                     que.push(ss);
    27                 else
    28                     st.push(ss);
    29             }
    30             else if(strcmp("Del",s) == 0)
    31             {
    32                 if(st.empty())
    33                 {
    34                     f = 1;
    35                 }
    36                 else
    37                 {
    38                     st.pop();
    39                     if(!que.empty())
    40                     {
    41                         st.push(que.front());
    42                         que.pop();
    43                     }
    44                 }
    45             }
    46             else if(strcmp("Out",s) == 0)
    47             {
    48                 if(que.empty())
    49                 {
    50                     f = 1;
    51                 }
    52                 else
    53                 {
    54                     que.pop();
    55                 }
    56 
    57             }
    58         }
    59         if(f == 1)
    60             printf("Error
    ");
    61         else
    62         {
    63             while(!st.empty())
    64             {
    65                 cout<<st.top()<<endl;
    66                 st.pop();
    67             }
    68         }
    69     }
    70     return 0;
    71 }
    View Code
  • 相关阅读:
    Sage CRM升级后的问题跟进
    js 控制滚动条位置
    初学Jquery插件制作:在SageCRM的查询屏幕隐藏部分行的功能
    [转摘] Reporting Service 200
    js数组去重复项
    JavaScript tips 1024 * 768
    javascript 的 replace 函数
    the secret of sagecrm urls
    Sage CRM 自增ID的方案和遇到的问题
    EXTJS 可编辑列表的时间编辑问题
  • 原文地址:https://www.cnblogs.com/LK1994/p/3150226.html
Copyright © 2011-2022 走看看