SDUT -refresh的停车场(栈和队列)

来源:互联网 发布:游戏王软件 编辑:程序博客网 时间:2024/05/16 16:15


题目描述

 refresh最近发了一笔横财,开了一家停车场。由于土地有限,停车场内停车数量有限,但是要求进停车场的车辆过多。当停车场满时,要进入的车辆会进入便道等待,最先进入便道的车辆会优先
进入停车场,而且停车场的结构要求只出去的车辆必须是停车场中最后进去的车辆。现告诉你停车场容量N以及命令数M,以及一些命令(Add num 表示车牌号为num的车辆要进入停车场或便道,
Del 表示停车场中出去了一辆车,Out 表示便道最前面的车辆不再等待,放弃进入停车场)。假设便道内的车辆不超过1000000.

输入

 首先输入N和M(0< n,m <200000),接下来输入M条命令。

输出

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

示例输入

2 6Add 18353364208Add 18353365550Add 18353365558Add 18353365559DelOut

示例输出

1835336555818353364208
用一个栈和一个对列模拟一下就好了。。数据好弱
#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <string>#include <cctype>#include <vector>#include <cstdio>#include <cmath>#include <deque>#include <stack>#include <map>#include <set>#define ll long long#define maxn 1010#define pp pair<int,int>#define INF 0x3f3f3f3f#define max(x,y) ( ((x) > (y)) ? (x) : (y) )#define min(x,y) ( ((x) > (y)) ? (y) : (x) )using namespace std;int n,m,top,st,en;char s[300010][33],q[300010][33];int main(){while(~scanf("%d%d",&n,&m)){int ok=1;top=0;st=0;en=0;char op[4],x[33];for(int i=1;i<=m;i++){scanf("%s",op);if(!strcmp(op,"Add")){scanf("%s",x);if(top<n)strcpy(s[top++],x);elsestrcpy(q[en++],x);}else if(!strcmp(op,"Del")){if(top){top--;if(st<en)strcpy(s[top++],q[st++]);}elseok=0;}else if(!strcmp(op,"Out")){if(st<en)st++;elseok=0;}}if(ok){for(int i=top-1;i>=0;i--)printf("%s\n",s[i]);}elseputs("Error");}return 0;}


1 0
原创粉丝点击