#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <malloc.h>
using namespace std;
struct BUS
{
int num;
int intime;
int outtime;
}bus[10000],buss[1000];
struct seq//停车场
{
int bus[10000];
int top;
};
struct seqq
{
int buss[1000];
int topp;
};
struct Biandao
{
int data;
int time;
int num;
struct Biandao *next;
};
struct biandao
{
Biandao *first;
Biandao *rear;
}biandao;
int main()
{
int x,t;
int n;
printf("请输入停车场车位数量n:\n");
cin >> n;
char a[5];
seq s;
s.top=0;
seqq ss;
ss.topp=0;
biandao.first=NULL;
biandao.rear =NULL;
int num = 0;
printf("请输入操作: 车牌号: 时间:\n");
while (cin >> a)
{
if ( !strcmp (a,"A"))
{
cin>>x>>t;
if ( s.top >= n )//如果停车场已满
{
Biandao *p;
p=(Biandao *)malloc(sizeof(Biandao));
p->data=x;
p->time=t;
num++;
p->next=NULL;
if (biandao.rear != NULL)
biandao.rear->next=p;
biandao.rear=p;
if (biandao.first==NULL)
biandao.first=p;
printf("在便道的第%d位置\n",num);
}
else//停车场未满
{
bus[s.top].num=x;
bus[s.top].intime=t;
printf("停车场的第%d位置\n",s.top+1);
s.top++;
}
}
else if (!strcmp (a,"D"))
{
cin>>x>>t;
if (s.top == 0)
{
printf("输入错误 重新输入\n");
}
else
{
int nu;
for (int i=0;i<=s.top;i++)
{
if (bus[i].num == x)
{
nu=i;
}
}
bus[nu].outtime=t;
printf("停留时间%d, 费用 %d \n", bus[nu].outtime - bus[nu].intime ,bus[nu].outtime - bus[nu].intime );
for (int i=nu ;i<=s.top;i++)//出停车站
{
bus[i]=bus[i+1];
}
s.top--;
if (biandao.first!=NULL)//如果便道上有车
{
bus[s.top].num = biandao.first->data;
bus[s.top].intime = t;
s.top++;
num--;
Biandao *q;
q=biandao.first;
biandao.first=biandao.first->next;
free(q);
}
}
}
else if(!strcmp (a,"E"))
{
break;
}
else
{
printf("输入有误 重新输入\n");
}
}
return 0;
}
tingchechang.zip_1:64tingchechang_停车管理_大qingchechang的_栈和队列
版权申诉
182 浏览量
2022-09-15
00:00:51
上传
评论
收藏 1KB ZIP 举报
御道御小黑
- 粉丝: 61
- 资源: 1万+