주차장 프로그램 - 자체 입력 시간

#include 
#include 
#include 
#include 
#define maxlen 15
#define max_stop 2
#define max_pave 3
#define price 5//     5 
typedef struct
{
    char name[maxlen];
    int inhour;
    int inminute;
    int outhour;
    int outminute;
} Car;
typedef struct
{
    Car data[max_stop];
    int top;
} Stack_Car,Stack_Carhelp;

typedef struct
{
    Car data[max_pave-1];
    int front;
    int rear;
    int cout;
} Queue_Car;

Stack_Car *c;//   
Stack_Carhelp *h;//   
Queue_Car *p;//  
char carname[maxlen];
int tempih[max_stop];//           
int tempim[max_stop];//           
int tempoh;//          
int tempom;//          
int totaltime;
Stack_Car *init()//    
{
    Stack_Car *car=(Stack_Car*)malloc(sizeof(Stack_Car));
    //Stack_Car *car;
    car->top=-1;
    return car;
}
Queue_Car *init1()//     
{
    Queue_Car *car=(Queue_Car*)malloc(sizeof(Queue_Car));
    //Queue_Car *car;
    car->front=car->rear=max_pave-1;
    car->cout=0;//         
    return car;
}
void Car_into_pave(Queue_Car *p,char name[maxlen])//      
{
    if(p->cout>0&&p->front==(p->rear+1)%max_pave)//    
    {
        printf("    ,      ~
"); return; } else { p->rear=(p->rear+1)%max_pave; p->cout++; strcpy(p->data[p->rear].name,carname); printf(" %s
",carname); printf(" %s %d
",carname,p->rear+1);// 1 } } void Car_into_stack()// { printf(" :
"); scanf(" %s",carname); if(c->top==max_stop-1)// Car_into_pave(p,carname); else { printf(" , (h,m):
"); c->top++; scanf(" %d:%d",&c->data[c->top].inhour,&c->data[c->top].inminute);// tempih[c->top]=c->data[c->top].inhour; tempim[c->top]=c->data[c->top].inminute;// strcpy(c->data[c->top].name,carname);// printf(" %s
",carname); printf(" %s %d
",carname,c->top+1); } } void Car_mid() { int i, find = 0; while(c->top>=0) { if(strcmp(c->data[c->top--].name,carname)==0)// , { find = 1; break; } else { strcpy(h->data[++h->top].name,c->data[c->top+1].name);// printf(" %s
",c->data[c->top+1].name); } } if(!find)// , c->top+1 { printf(" !
"); while(h->top>=0)// { strcpy(c->data[++c->top].name,h->data[h->top--].name); } return; } else { printf(" :
"); scanf("%d:%d",&c->data[c->top+1].outhour,&c->data[c->top+1].outminute); tempoh=c->data[c->top+1].outhour;// tempom=c->data[c->top+1].outminute;// if(tempih[c->top+1]==tempoh)// , { totaltime=1; } else { totaltime=tempoh-tempih[c->top+1]+(tempom>tempim[c->top+1]?1:0);// , } printf(" %s
",c->data[c->top+1].name); printf(" %d , %d
",totaltime,price*totaltime); if(c->top+1>=0) { for(i=c->top+1; itop+1 , { tempih[i]=tempih[i+1];// tempim[i]=tempim[i+1];// } tempih[max_stop-1]=tempoh; tempim[max_stop-1]=tempom;// ; , } while(h->top>=0)// { strcpy(c->data[++c->top].name,h->data[h->top--].name); } if(c->top<=max_stop-1&&p->cout>0)// { // if(p->cout==0) // break;// // else p->front=(p->front+1)%max_pave; strcpy(c->data[++c->top].name,p->data[p->front].name);// printf(" %s %d
",p->data[p->front].name,c->top+1);// , p->data[p->front].name , ( ) if(p->cout>1) { for(i=p->front+1; icout; i++) { strcpy(p->data[i-1].name,p->data[i].name);// , , } p->rear--; p->front--;// , ,display p->cout--; } else// , , , 1 { p->rear=max_pave-1; p->front=max_pave-1; p->cout=0; } } } } void Car_leave()// { printf(" :
"); scanf(" %s",carname); if(c->top<0)// printf(" !
"); else Car_mid(); } void Display() { int i; if(c->top==-1) { printf("
"); } else { printf(" %d , %d , %d
",max_stop,c->top+1,p->cout); if(p->cout>0) { printf(" :
"); for(i=0; i<=c->top; i++) { printf("%d :%s
",i+1,c->data[i].name); } printf(" :
"); for(i=0; icout; i++) { printf("%d :%s
",i+1,p->data[i].name); } } else { printf(" :
"); for(i=0; i<=c->top; i++) { printf("%s
",c->data[i].name); } printf(" !
"); } } } void welcome() { printf ("\t******************* ***********************
"); printf ("\t %d , %d , %d
",max_stop, c->top+1, p->cout); printf ("\t********************************************************
"); printf ("\t---------------Welcome to our Car Parking---------------
"); printf ("\t* 1.Parking *
"); printf ("\t* 2.leaving *
"); printf ("\t* 3.situation *
"); printf ("\t* 4.exit *
"); printf ("\t--------------------------------------------------------
"); } int main() { totaltime=0; c=init(); h=init(); p=init1();// while(1) { system("cls");// welcome(); int i, choice=0; scanf ("%d", &i); if (i==1) Car_into_stack(); if (i==2) Car_leave(); if (i==3) Display(); if (i==4) break; printf (" 1:
"); fflush(stdin); scanf("%d", &choice); while (choice != 1) { printf(" ,
"); scanf("%d", &choice); } } return 0; }

좋은 웹페이지 즐겨찾기