SDUT2088refresh的停车场

#include<bits/stdc++.h>
using namespace std;
int f(char z[5])
{
    if(strcmp(z,"Add")==0)
        return 0;
    else if(strcmp(z,"Del")==0)
        return 1;
    else if(strcmp(z,"Out")==0)
        return 2;
}
void refresh(int n,int m)
{
    queue<long long int>Q;
    stack<long long int>S;
    int flag=1;
    while(m--)
    {
        char a[5];
        scanf("%s",a);
        if(f(a)==0)///Add
        {
            long long int num;
            scanf("%lld",&num);
            if(S.size()<n)
                S.push(num);
            else
                Q.push(num);
        }
        else if(f(a)==1)///Del
        {
            if(S.empty())
                flag=0;
            else
            {
                S.pop();
                if(!Q.empty())
                {
                    long long int t=Q.front();
                    Q.pop();
                    S.push(t);
                }
            }
        }
        else if(f(a)==2)///Out
        {
            if(Q.empty())
                flag=0;
            else
                Q.pop();
        }
    }
    if(!flag)
        printf("Error\n");
    else
        while(!S.empty())
        {
            printf("%lld\n",S.top());
            S.pop();
        }
}
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
        refresh(n,m);
}

    原文作者:停车场模拟问题
    原文地址: https://blog.csdn.net/nar666/article/details/52132212
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞