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


题目描述

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

输入

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

输出

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

示例输入

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

示例输出

18353365558
18353364208
用一个栈和一个对列模拟一下就好了。。数据好弱
#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);
				else
					strcpy(q[en++],x);
			}
			else if(!strcmp(op,"Del"))
			{
				if(top)
				{
					top--;
					if(st<en)
					strcpy(s[top++],q[st++]);
				}
				else
				ok=0;
			}
			else if(!strcmp(op,"Out"))
			{
				if(st<en)
					st++;
				else
					ok=0;
			}
		}
		if(ok)
		{
			for(int i=top-1;i>=0;i--)
				printf("%s\n",s[i]);
		}
		else
			puts("Error");
	}
	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值