refresh的停车场

refresh的停车场 

~题目要求~

输入

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

结果

18353365558
18353364208

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<stack>
#include<string>
#include <iostream>

using namespace std;

int main()
{
    int n,m,k;
    string str, tel;
    while(~scanf("%d%d",&n,&m))
    {
        k=0;
        bool flag=false;//bool只有false和true
        queue<string>Q;//字符串不能以%s输出
        stack<string>P;
        while(m--)
        {
            cin>>str;
            if(str=="Add")//定义为string可直接比较str=="Add"
            {
                cin>>tel;
                if(k<n)
                {
                    P.push(tel);
                    k++;
                }
                else
                    Q.push(tel);
            }
            if(str=="Del")
            {
                if(!P.empty())
                {
                    P.pop();
                    if(!Q.empty())
                    {
                        P.push(Q.front());
                        Q.pop();
                    }
                    else
                        k--;
                }
                else flag=true;

            }
            if(str=="Out")
            {
                if(!Q.empty())
                    Q.pop();
                else flag=true;
            }
        }
        if(flag)
            cout<<"Error\n";
        else
        {
            while(!P.empty())
            {
                cout<<P.top()<<"\n";
                P.pop();
            }
        }
    }
    return 0;
}

  

  

posted @ 2013-08-02 16:43  Locke_Q  阅读(255)  评论(0编辑  收藏  举报