3,881
社区成员
发帖
与我相关
我的任务
分享#include "stdio.h"
#include "stdlib.h"
#include <stack>
#define MAXSIZEPARK 2
#define MAXSIZETEMPLINE 2
#define COST 20
typedef struct
{
int *top;
int *base;
int stacksize;
}SqStack; //定义堆栈
typedef struct
{
int ID;
int time;
char option;
}carinfo; //定义了车的类型
void initstack(SqStack &s)
{
s.base=(int *)malloc(MAXSIZEPARK *sizeof(carinfo));
if(!s.base)exit(1);
s.top=s.base;
s.stacksize=MAXSIZEPARK;
}
int push(SqStack &s,carinfo t)
{
if(s.top-s.base>=s.stacksize)
{
printf("停车场已满将车放到临时车道\n");
return 0;
}
else
{
//*s.top++=*t;
return 1;
}
}
int pop(SqStack &s,carinfo &t)
{
if(s.base==s.top)
{
printf("停车场没有车\n");
return 0;
}
else
{
//*t=*s.top--;
return 1;
}
}
int main(void)
{
carinfo car,b;
SqStack parking,temp;
initstack(parking);
initstack(temp);
printf("||************ | 停 车 场 管 理 系 统 |*************||\n");
printf("||******************* | 说 明 |********************||\n");
printf("停车场可停放%d辆车! 便道可停放%d辆车! 停车每小时%d元!\n\n",MAXSIZEPARK,MAXSIZETEMPLINE,COST);
printf("||***************************************************||\n");
while(1)
{
printf("\n请输入A/D/E,车牌号,时刻:");
scanf("%c,%d,%d",&car.option,&car.ID,&car.time);
if(car.option=='e'||car.option=='E')
exit(0);
else
switch(car.option)
{
case 'a':
case 'A':
{
if(push(parking,car)==0)
printf("success");
else
printf("车牌号为%d的车,%d时开进停车场!\n",car.ID,car.time);
}
break;
case 'd':
case 'D':
while(car.ID!=b.ID)
{
pop(parking,b);
push(temp,b);
}
}
}
return 0;
}//真乱套啊。逻辑自己在看看,没有改逻辑