⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 part.txt

📁 停车场代码
💻 TXT
字号:
#include<stdinorout.h>
#include<coninorout.h>
#include<malloc.h>
#define  null  0
typedef struct{
	int inorout;
	int carNUMBER;
	float time;
	int next;
}partingLot[3];
partingLot S,Temp;
int top,base;
typedef struct node{
	int inorout;
	int carNUMBER;
	struct node * next;
}sideband,* psideband;
psideband Q,front,rear;
void init(partingLot &S,psideband &Q){
	for(int i=0;i<10;i++)   S[i].next=i+1;
	S[0].carNUMBER=0;
	top=base=0;
	Q=( psideband )malloc(sizeof(sideband));
	Q->next=null;
	front=rear=Q;
	Q->carNUMBER=0;
}
int locate_s(partingLot &S,int no){
	for(int p=S[base].next,i=1;p!=top;p=S[p].next,i++)
		if(no==S[p].carNUMBER) return i;
	return 0;
}
void pop(partingLot &S,int pos){
	for(int i=1;i<=S[0].carNUMBER;i++)
		if(S[i].next==pos)		S[i].next=S[pos].next;
    S[pos].next=S[top].next;		
	S[top].next=pos;
	S[0].carNUMBER--;
}
int push(partingLot &S,int carNUMBER,float time){
	int p=S[top].next;
	S[p].time=time;
	S[p].carNUMBER=carNUMBER;
	top=p;
	return ++S[0].carNUMBER;
}
int locate_q(psideband &Q,int no){
	psideband p=front;
	for(int i=1;p!=rear;p=p->next,i++)
		if(no==p->carNUMBER)  return i;
	return 0;
}
int inQueue(psideband &Q,int no){
    psideband p=(psideband)malloc(sizeof(sideband));
	rear->next=p;
	p->next=null;
	rear=p;
	p->carNUMBER=no;
	return ++(Q->carNUMBER);
}
int outQueue(psideband &Q,int pos){
	psideband p=front->next,q=front;
	int i=1,j;
	while(i<pos){
		i++;
		q=p;
		p=p->next;
	}
	Q->carNUMBER--;
	q->next=p->next;
	j=p->carNUMBER;
	free(p);
	return j;
}
int main(){
	int flag=1,i,inout,carNUMBER,j;
	char s_time[6];
	float time;
	init(S,Q);
    printf("\t\t\t欢迎使用停车场信息查询系统\n\n\t\t\t作者:王洵 殷帆 翟后波\n\n");
	while(flag){
		i=0;
		printf("\t1    进入\n\t0    出去\n\t您的选择:  ");
		scanf("%d",&inout);
		printf("\t您的车号:  ");
		scanf("%d",&carNUMBER);
		printf("\t请输入时间  (格式如 00:00):   ");
		scanf("%s",s_time);
		time=(float)(10*s_time[3]+s_time[4]);
		time/=60.0;
		time+=(10*s_time[0]+s_time[1]);
		if(inout){
			if(S[0].carNUMBER==2)   
				printf("\t您的车在外道第%d个位置\n",inQueue(Q,carNUMBER));
			else  
				printf("\t您的车在停车场内第%d个位置\n",push(S,carNUMBER,time));
		}
		else if(  !(  i==locate_s(S,carNUMBER)  )  ){
            i=locate_s(S,carNUMBER);
			printf("\t您的应付款为:%.2f\n",30*(time-S[i].time));
	        pop(S,i);
			if(Q->carNUMBER){	
				carNUMBER=outQueue(Q,1);
				printf("\t%d号车在%s进入停车场内第%d个位置\n",carNUMBER,s_time,push(S,carNUMBER,time));
			}
		}
		else if(i==locate_q(Q,carNUMBER)){
            i=locate_q(Q,carNUMBER);
			printf("\n\t您的车在外道第%d个位置\n",i);
			j=outQueue(Q,i);
		}
     	printf("\tContinue?    1-->yes,0-->no\n");
		printf("\t您的选择:      ");
        scanf("%d",&flag);     
	}
    return 0;
}
	


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -