zoukankan      html  css  js  c++  java
  • refresh的停车场 分类: 栈和队列 2015-06-18 17:13 26人阅读 评论(0) 收藏

    refresh的停车场

    TimeLimit: 1000ms Memory limit: 65536K

    题目描述

    refresh最近发了一笔横财,开了一家停车场。由于土地有限,停车场内停车数量有限,但是要求进停车场的车辆过多。当停车场满时,要进入的车辆会进入便道等待,最先进入便道的车辆会优先

    进入停车场,而且停车场的结构要求只出去的车辆必须是停车场中最后进去的车辆。现告诉你停车场容量N以及命令数M,以及一些命令(Addnum 表示车牌号为num的车辆要进入停车场或便道,

    Del表示停车场中出去了一辆车,Out表示便道最前面的车辆不再等待,放弃进入停车场)。假设便道内的车辆不超过1000000.

    输入

    输入为多组数据,每组数据首先输入NM0< n,m <200000),接下来输入M条命令。

    输出

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

    示例输入

    26

    Add18353364208

    Add18353365550

    Add18353365558

    Add18353365559

    Del

    Out

    示例输出

    18353365558

    18353364208

    #include <map>
    #include <set>
    #include <cmath>
    #include <stack>
    #include <queue>
    #include <time.h>
    #include <cstdio>
    #include <cctype>
    #include <vector>
    #include <string>
    #include <climits>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <algorithm>
    #define RR freopen("input.txt","r",stdin)
    #define WW freopen("output.txt","w",stdout)
    #define INF 0x3f3f3f3f
    
    using namespace std;
    
    int main()
    {
        int n,m;
        int ans;
        string con;
        string num;
        while(~scanf("%d %d",&n,&m))
        {
            stack<string>park;
            queue<string>street;
            ans=0;
            bool flag=true;
            for(int i=0;i<m;i++)
            {
                cin>>con;
                if(con=="Add")
                {
                    cin>>num;
                    if(ans<n)
                    {
                       park.push(num);
                       ans++;
                    }
                    else
                    {
                        street.push(num);
                    }
                }
                else if(con=="Del")
                {
                    if(!park.empty())
                    {
                        park.pop();
                        ans--;
                    }
                    else
                    {
                        flag=false;
                    }
                    if(!street.empty()&&ans<n)//经入停车场
                    {
                        num=street.front();
                        street.pop();
                        park.push(num);
                        ans++;
                    }
                }
                else if(con=="Out")
                {
                    if(!street.empty())
                    {
                        street.pop();
                    }
                    else
                    {
                        flag=false;
                    }
                }
            }
            if(!flag)
            {
                cout<<"Error"<<endl;
            }
            else
            {
                while(!park.empty())
                {
                    cout<<park.top()<<endl;
                    park.pop();
                }
            }
        }
        return 0;
    }


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    C++面向对象高级编程(下)第二周-Geekband
    C++面向对象高级编程(下)第一周-Geekband
    C++面向对象高级编程(下)-Geekband
    堆,栈,内存管理, 拓展补充-Geekband
    C++面向对象高级编程(上)-Geekband
    MFC 多屏显示
    Open CASCADE Technology: IGES Support
    JAVA反射
    HashMap
    Linux 系统编程
  • 原文地址:https://www.cnblogs.com/juechen/p/4722016.html
Copyright © 2011-2022 走看看