苏州建站仿站,o2o网站建设咨询,wordpress文章,怎样在百度上做网站题目描述 refresh最近发了一笔横财#xff0c;开了一家停车场。由于土地有限#xff0c;停车场内停车数量有限#xff0c;但是要求进停车场的车辆过多。当停车场满时#xff0c;要进入的车辆会进入便道等待#xff0c;最先进入便道的车辆会优先 进入停车场#xff0c;而且… 题目描述
refresh最近发了一笔横财开了一家停车场。由于土地有限停车场内停车数量有限但是要求进停车场的车辆过多。当停车场满时要进入的车辆会进入便道等待最先进入便道的车辆会优先 进入停车场而且停车场的结构要求只出去的车辆必须是停车场中最后进去的车辆。现告诉你停车场容量N以及命令数M以及一些命令Add num 表示车牌号为num的车辆要进入停车场或便道 Del 表示停车场中出去了一辆车Out 表示便道最前面的车辆不再等待放弃进入停车场。假设便道内的车辆不超过1000000. 输入
输入为多组数据每组数据首先输入N和M0 200000接下来输入M条命令。输出
输入结束后如果出现停车场内无车辆而出现Del或者便道内无车辆而出现Out,则输出Error,否则输出停车场内的车辆最后进入的最先输出无车辆不输出。示例输入 2 6
Add 18353364208
Add 18353365550
Add 18353365558
Add 18353365559
Del
Out 示例输出 18353365558
18353364208
#include stdio.h
#include stdlib.h
#include string.h
#define stackmax 10000
#define stacknum 11111
typedef long long int ElenType;
typedef struct
{
ElenType *base;
ElenType *top;
int stacksize;
}SqStack;
int InitStack(SqStack S)//栈的初始化
{
S.base(ElenType *)malloc(sizeof(ElenType)*stacknum);
if(!S.base) exit(0);
S.topS.base;
S.stacksizestacknum;
return 1;
}
void push(SqStack S,ElenType e)//进栈
{
if(S.top-S.baseS.stacksize)
{
S.base(ElenType *)realloc(S.base,sizeof(ElenType)*(stacknumstackmax));
if(!S.base) exit(0);
S.topS.baseS.stacksize;
S.stacksizestackmax;
}
*S.tope;
}
int pop(SqStack S)//出栈
{
if(S.topS.base)
return 0;
S.top--;
return 1;
}
int StackEmpty(SqStack S)//判断栈是否为空栈
{
if(S.topS.base)
return 1;
else
return 0;
}
void print(SqStack S)//栈的元素的输出
{
while(!StackEmpty(S))
{
S.top--;
printf(%lld\n,*S.top);
}
}
typedef long long int QElemType;
typedef long long int Status;
typedef struct QNode
{
QElemType data;
QNode *next;
} QNode, *Queueptr;
typedef struct
{
Queueptr front;
Queueptr rear;
} LinkQueue;
Status InitQueue (LinkQueue q)//队的初始化
{
q.frontq.rear(Queueptr)malloc(sizeof(QNode));
if(!q.front) exit(0);
q.front-nextNULL;
return 1;
}
Status EnQueuer(LinkQueue q, QElemType e)//进队
{
Queueptr p;
p(Queueptr)malloc(sizeof(QNode));
if(!p) exit(0);
p-datae;
p-next NULL;
q.rear-nextp;
q.rearp;
return 1;
}
Status DeQueuel(LinkQueue Q,QElemType e)//出队
{
Queueptr p;
if(Q.frontQ.rear)
return 0;
pQ.front-next;
ep-data;
Q.front-nextp-next;
if(Q.rearp)
Q.rearQ.front;
free(p);
return 1;
}
int EmptyQueue(LinkQueue q)//判断是否为空队
{
if(q.frontq.rear)
return 1;
else
return 0;
}
QElemType Queuelength(LinkQueue q)//队的长度‘
{
QElemType i0;
Queueptr p;
pq.front;
while(p!q.rear)
{
i;
pp-next;
}
return i;
}
int main()
{
long int i,n,m;
long long int num;
char c[4];
while(~scanf(%ld%ld,n,m))
{
SqStack S;
InitStack(S);
LinkQueue Q;
InitQueue(Q);
int flag1;
for(i1; im; i)
{
scanf(%s, c);
if(strcmp(c,Add)0)
{
scanf(%lld,num);
if(S.top-S.basen)//判断栈停车位是否已满
push(S, num);
else
EnQueuer(Q,num);
}
if(strcmp(c,Del)0)
{
if(StackEmpty(S))
flag0;//标记不合法的命令
else
{
pop(S);
DeQueuel(Q,Q.front-data);
push(S,Q.front-data);
}
}
if(strcmp(c,Out)0)
{
if(EmptyQueue(Q))
flag0;//标记不合法的命令
else
{
DeQueuel(Q,Q.front-data);
}
}
}
if(flag0)
printf(Error\n);
else
print(S);//栈内元素的输出;
}
}
#include iostream
#include cstdio
#include cstdlib
#include cstring
#include queue
#include stack
using namespace std;
int main()
{
int N,M,x,t;
while(~scanf(%d %d,N,M))
{
char minglin[10],num[100];
queuestringqd;//队列的定义
stackstringsz;//栈的定义
t0;
while(M--)
{
scanf(%s,minglin);
if(minglin[0]A)
{
scanf(%s,num);
xsz.size();//栈的长度
if(xN)
sz.push(num);//进栈
else
qd.push(num);//进队
}
else if(minglin[0]D)
{
if(sz.empty())//空栈
t1;
else
{
sz.pop();//出栈
if(!qd.empty())
{
sz.push(qd.front());//进栈
qd.pop();//出队
}
}
}
else if(minglin[0]O)
{
if(qd.empty())
t1;
else
qd.pop();
}
}
if(t1)
printf(Error\n);
else
{
while(!sz.empty())
{
coutsz.top()endl;
sz.pop();
}
}
}
return 0;
}