refresh的停车场
来源:互联网 发布:老k户型方案优化平台 编辑:程序博客网 时间:2024/04/29 04:17
refresh的停车场
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
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 <stdio.h>#include <stdlib.h>#include <string.h>long long s[2123456];long long b[1123456];int main(){ int n, m; while(~scanf("%d %d", &n, &m)){ char ss[10]; int flag = 0; int head = 0,tail = 0; int top = -1; long long x; int j; for(int i = 0;i < m;i++){ scanf("%s", ss); if(strcmp(ss,"Add")==0){ scanf("%lld", &x); if(top<n-1){ s[++top] = x; }else { b[tail++] = x; } }else if(strcmp(ss,"Del")==0){ if(top==-1){ flag= 1; }else { top--; while(top < n-1&&head<tail){ //栈不满&&队列不为空 s[++top] = b[head]; head++; } } }else if(strcmp(ss,"Out")==0){ if(head<tail){ head++; }else { flag = 1; } } } if(flag){ printf("Error\n"); }else { for(j = top;j>=0;j--){ printf("%lld\n", s[j]); } } } return 0;}
0 0
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场 SDUT
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- refresh的停车场
- Ruby语言基础学习八:Ruby哈希、时间、
- 均分纸牌
- 2016郑州大学ACM/ICPC训练赛 A 词法分析器
- JDK8 ——lambda表达式
- 公司合并
- refresh的停车场
- BestCoder Round #78 (div.2)1002 CA Loves GCD
- android studio中activity_main.xml 和content_main.xml的区别
- nodejs npm常用命令
- service builder不会自动建表/更新字段
- 三星Mega 6.3(i9200)删除kingroot
- 4.3日清明前一天
- theano logistic regression讲解
- 第5周项目1-三角形类雏形(3)