• 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
    ";
            else
            {
                while(!P.empty())
                {
                    cout<<P.top()<<"
    ";
                    P.pop();
                }
            }
        }
        return 0;
    }
    

      

      

  • 相关阅读:
    最短路小变形
    最短路
    bfs + 路径输出
    优先队列
    dijkstra
    重载运算符-operator
    最短路
    二分图匹配
    依赖型的关系建立
    string 类
  • 原文地址:https://www.cnblogs.com/guoyongzhi/p/3233016.html
Copyright © 2020-2023  润新知