SDOTOJ2088 refresh的停车场(栈和队列)
Description
现告诉你停车场容量N以及命令数M,以及一些命令(Add num 表示车牌号为num的车辆要进入停车场或便道。
如果便道内的车辆不超过1000000.
Input
Output
Sample Input
2 6
Add 18353364208
Add 18353365550
Add 18353365558
Add 18353365559
Del
Out
Sample Output
18353365558
18353364208
Hint
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<stack>
#include<queue> using namespace std; string a[2000021],b[2000021];
int n,m; int main()
{
while(cin >> n >> m)
{
int flag = 0;
string str,num;
int h = 0,k1 = 0,k2 = 0;
for(int i=0; i<m; i++)
{
cin >> str;
if(str == "Add")
{
cin >> num;
if(h<n)
{
a[++h] = num;
}
else
{
b[++k2] = num;
} }
else if(str == "Del")
{
if(h<=0)
{
flag = 1;
}
else if(k2 > k1)
{ a[h] = b[++k1];
}
else if(k2<=k1)
{
h--;
} }
else if(str == "Out")
{
if(k2 <= k1)
{
flag = 1;
}
else
{
k1++;
} } }
if(h>0 && flag == 0)
{
while(h>0)
{
cout << a[h] << endl;
h--;
}
}
else if(flag == 1)
{
cout << "Error" << endl;
} }
return 0;
}
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<stack>
#include<queue> using namespace std; int n,m; int main()
{
while(cin >> n >> m)
{
stack<string>a;
queue<string>b;
int flag = 0;
string str,num;
for(int i=0; i<m; i++)
{
cin >> str;
if(str == "Add")
{
cin >> num;
if(a.size() == n)
{
b.push(num);
}
else
{
a.push(num);
}
}
else if(str == "Del")
{ if(a.empty())
{
flag = 1;
}
else
{
a.pop();
if(!b.empty())
{
a.push(b.front());
b.pop();
}
}
}
else if(str == "Out")
{ if(b.empty())
{
flag = 1;
}
else
{
b.pop();
}
}
// printf("h = %d k1 = %d k2 = %d\n",h,k1,k2);
} if(flag == 1)
{
cout << "Error" << endl;
}
else
{
while(!a.empty())
{
cout << a.top() << endl;
a.pop();
} }
}
return 0;
}
SDOTOJ2088 refresh的停车场(栈和队列)的更多相关文章
- refresh的停车场(栈和队列的STL)
refresh的停车场 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 refresh近期发了一笔横財,开了一家停车场. 因 ...
- SDUT-2088_数据结构实验之栈与队列十一:refresh的停车场
数据结构实验之栈与队列十一:refresh的停车场 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description refresh最近发 ...
- 数据结构实验之栈与队列十一:refresh的停车场
数据结构实验之栈与队列十一:refresh的停车场 Description refresh最近发了一笔横财,开了一家停车场.由于土地有限,停车场内停车数量有限,但是要求进停车场的车辆过多.当停车场满时 ...
- refresh的停车场 分类: 栈和队列 2015-06-18 17:13 26人阅读 评论(0) 收藏
refresh的停车场 TimeLimit: 1000ms Memory limit: 65536K 题目描述 refresh最近发了一笔横财,开了一家停车场.由于土地有限,停车场内停车数量有限,但是 ...
- SDUT OJ 2088 refresh的停车场
refresh的停车场 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 refresh最近发了一笔横财,开了一家停车场.由于土地 ...
- c/c++ 栈与队列实现车库的出入与收费
/* 设停车场是一个可停放n辆车的狭长通道,且只有一个大门可供汽车进出.汽车在停车场内按车辆到达时间的先后顺序,依次由北向南排列 (大门在最南端,最先到达的第一辆车停放在车场的最北段),若停车厂内 ...
- 学习javascript数据结构(一)——栈和队列
前言 只要你不计较得失,人生还有什么不能想法子克服的. 原文地址:学习javascript数据结构(一)--栈和队列 博主博客地址:Damonare的个人博客 几乎所有的编程语言都原生支持数组类型,因 ...
- [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)
再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...
- 剑指Offer面试题:6.用两个栈实现队列
一.题目:用两个栈实现队列 题目:用两个栈实现一个队列.队列的声明如下,请实现它的两个函数appendTail和deleteHead,分别完成在队列尾部插入结点和在队列头部删除结点的功能. 原文是使用 ...
随机推荐
- Spring+Spring MVC+MyBatis
Spring+Spring MVC+MyBatis 目录 一.新建一个基于Maven的Web项目 二.创建数据库与表 三.添加依赖包 四.新建POJO实体层 五.新建MyBatis SQL映射层 六. ...
- jQuery validate (转载)
转自:http://blog.sina.com.cn/s/blog_608475eb0100h3h1.html jQuery校验 官网地址:http://bassistance.de/jquery-p ...
- aix 小机运维
zzbank 一个月折腾总结小总结:#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++#+ Ruiy-ge;#+#+ Te ...
- aix installp软件包管理工具
软件可以安装成两种状态:applied和committed.Applied状态保存了原来以前版本的软件,它把以前版本存储在/usr/lpp/PackageName目录下.这种方式可以回滚到以前的软件版 ...
- 如果在文档已完成加载后执行 document.write,整个 HTML 页面将被覆盖
<!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <p>My F ...
- JQuery(下)
26.jQuery 中的 DOM 操作 )DOM(Document Object Model—文档对象模型):一种与浏览器, 平台, 语言无关的接口, 使用该接口可以轻松地访问页面中所有的标准组件 ) ...
- Spring、AOP详解
如何配置AOP查看:Spring.Hello AOP 1.对于拦截规则@Pointcut的介绍: @Pointcut("execution (* cn.raffaello.service.. ...
- POJ1325 Machine Schedule 【二分图最小顶点覆盖】
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11958 Accepted: 5094 ...
- AngularJs(八) 过滤器filter创建
大纲 示例 过滤器的使用 创建过滤器 demo 这是整个示例demo 1.filter.js文件 angular.module("exampleApp", []) .constan ...
- js格式化日期yyyyMMdd
先来一个土方法: <script>function getyyyyMMdd(){ var d = new Date(); var curr_date = d.getDate(); var ...