refresh的停车场
来源:互联网 发布:杨柘 知乎 编辑:程序博客网 时间:2024/06/09 19:31
refresh的停车场
TimeLimit: 1000ms Memory limit: 65536K
题目描述
refresh最近发了一笔横财,开了一家停车场。由于土地有限,停车场内停车数量有限,但是要求进停车场的车辆过多。当停车场满时,要进入的车辆会进入便道等待,最先进入便道的车辆会优先
进入停车场,而且停车场的结构要求只出去的车辆必须是停车场中最后进去的车辆。现告诉你停车场容量N以及命令数M,以及一些命令(Addnum表示车牌号为num的车辆要进入停车场或便道,
Del表示停车场中出去了一辆车,Out表示便道最前面的车辆不再等待,放弃进入停车场)。假设便道内的车辆不超过1000000.
输入
输入为多组数据,每组数据首先输入N和M(0< n,m <200000),接下来输入M条命令。
输出
输入结束后,如果出现停车场内无车辆而出现Del或者便道内无车辆而出现Out,则输出Error,否则输出停车场内的车辆,最后进入的最先输出,无车辆不输出。
示例输入
26
Add18353364208
Add18353365550
Add18353365558
Add18353365559
Del
Out
示例输出
18353365558
18353364208
#include <map>#include <set>#include <cmath>#include <stack>#include <queue>#include <time.h>#include <cstdio>#include <cctype>#include <vector>#include <string>#include <climits>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>#define RR freopen("input.txt","r",stdin)#define WW freopen("output.txt","w",stdout)#define INF 0x3f3f3f3fusing namespace std;int main(){ int n,m; int ans; string con; string num; while(~scanf("%d %d",&n,&m)) { stack<string>park; queue<string>street; ans=0; bool flag=true; for(int i=0;i<m;i++) { cin>>con; if(con=="Add") { cin>>num; if(ans<n) { park.push(num); ans++; } else { street.push(num); } } else if(con=="Del") { if(!park.empty()) { park.pop(); ans--; } else { flag=false; } if(!street.empty()&&ans<n)//经入停车场 { num=street.front(); street.pop(); park.push(num); ans++; } } else if(con=="Out") { if(!street.empty()) { street.pop(); } else { flag=false; } } } if(!flag) { cout<<"Error"<<endl; } else { while(!park.empty()) { cout<<park.top()<<endl; park.pop(); } } } return 0;}
0 0
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场 SDUT
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- 图像处理复习2——图像傅立叶变换和频域滤波
- 理解Javascript_15_作用域分配与变量访问规则,再送个闭包
- windows下 apache和tomcat集成配置
- ViewPager 详解(一)---基本入门
- z-index 解释 postion是否也为relative或者absolute
- refresh的停车场
- 关于域中计算机调取网络共享目录中图片的问题
- Oracle、MySql、SQLServer 数据分页查询
- django 模板里面for循环和forloop变量
- C++中const顶层指针与底层指针
- ios证书相关
- 精准调度,高速体验:移动防劫持D+详解
- 事件总线 —— otto的bus和eventbus对比分析
- js onload()与jQuery ready()方法区别