停车场管理
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#define FALSE 0
#define TRUE 1
#define MONEY 1
#define MAX_STOP 2
#define MAX_PAVE 2
typedef struct{
int time1;
int time2;
char plate[10];
}car;
typedef struct{
car stop[MAX_STOP-1];
int top;
}stopping;
typedef struct{
int count;
car pave[MAX_PAVE-1];
int front,rear;
}pavement;
typedef struct{
car help[MAX_STOP-1];
int top;
}buffer;
stopping s;
car c;
buffer b;
pavement p;
char C[10];
void stop_to_pave(){
if(p.count>0&&(p.front==(p.rear+1)%MAX_PAVE))
printf("便道已满\n");
else{
strcpy(p.pave[p.rear].plate,C);
p.rear=(p.rear+1)%MAX_PAVE;
p.count++;
printf ("牌照为%s的汽车停入便道上的%d的位置\n", C, p.rear - 1);
}
}
void car_come()
{
printf("请输入即将停车的车牌号\n");
scanf("%s",C);
if(s.top>=MAX_STOP-1)
stop_to_pave();
else
{
s.top++;
time_t t1;
long int t=time(&t1);
char*t2;
t2=ctime(&t1);
c.time1=t;
strcpy(s.stop[s.top].plate,C);
printf("牌照为%s的汽车停入停车位的%d车位,当前时间:%s\n",C,s.top+1,t2);
}
}
void stop_to_buff(){
while(s.top>=0)
{
if(0==strcmp(s.stop[s.top--].plate,C))
break;
strcpy(b.help[b.top++].plate,s.stop[s.top+1].plate);
printf ("牌照为%s的汽车暂时退出停车位\n", s.stop[s.top + 1].plate);
s.top--;
}
printf ("牌照为%s的汽车从停车场开走\n", s.stop[s.top + 1].plate);
while(b.top>=0)
{
strcpy(s.stop[s.top++].plate, b.help[b.top--].plate);
printf ("牌照为%s的汽车停回停车位%d车位\n", b.help[b.top + 1].plate, s.top + 1);
}
while (s.top<MAX_STOP-1)
{
if(p.count==0) break;
else
{
strcpy(s.stop[s.top++].plate,p.pave[p.front].plate);
printf ("牌照为%s的汽车从便道中进入停车位的%d车位\n", p.pave[p.front].plate, s.top+1);
p.front=(p.front+1)%MAX_PAVE;
p.count--;
}
}
}
void car_leave(){
printf("请输入即将离开的车牌号:\n");
scanf("%s",&C);
stop_to_buff();
time_t t1;
long int t=time(&t1);
c.time2=t;
char*t2;
t2=ctime(&t1);
printf("离开时间%s\n需付%ld元\n",t2,MONEY*(c.time2-c.time1)/10);
}
void welcome(){
printf("\t停车场共有%d个车位,当前停车场共有%d辆车,等候区共有%d辆车\n",MAX_STOP,s.top+1,(p.rear+MAX_PAVE-p.front)%MAX_PAVE);
printf("\t 1.停车 2.离开 3.返回 4.退出 \n");
}
int main(){
s.top = -1;
b.top = 0;
p.rear = 0;
p.count = 0;
p.front = 0;
while(1)
{
system("cls");
welcome();
int i,cho;
scanf("%d",&i);
if(i==1) car_come();
if(i==2) car_leave();
if(i==4) break;
scanf("%d",&cho);
if(cho==3)
continue;
}
return 0;
}