#include
#include
#define maxnumber 100
int index1=0,index2=0;
typedef struct cus{
char name[20];
int wait_time;
int arrive_time;
}Customer;
void input_time(int&a,int &b)
{
printf("请输入来的时间:");
scanf("%d:%d",&a,&b);
}
void change_timetype1(Customer *C)
{
int a,b;
input_time(a,b);
(*C).arrive_time=a*60+b;
}
void change_timetype2(Customer *C)
{
int a,b;
a=(*C).arrive_time%60;
b=(*C).arrive_time/60;
printf("%d:%d\n",b,a);
}
void input_name_and_waittime(Customer *C)
{
printf("请输入顾客的名字:");
scanf("%s",(*C).name);
printf("请输入顾客愿意的等待时间:");
scanf("%d",&(*C).wait_time);
}
void input_customer_information(Customer*C)
{
Customer *p=C;
for(int i=0;i
p++;
}
printf("请输入顾客的信息:\n");
change_timetype1(p);
input_name_and_waittime(p);
index1++;
index2=index1;
}
void putout_onecustomer(Customer*C)
{
for(int i=0;i<10;i++)
printf("******");
printf("\n");
printf(" %s %d ",(*C).name,(*C).wait_time);
change_timetype2(C);
printf("\n");
}
void putout_all(Customer*C)
{
int num=0;
for(int i=0;i<10;i++)
printf("******");
printf("\n");
printf(" 顾客名字 愿意等待时间 到达时间 \n");
while(num
putout_onecustomer(C++);
num++;
}
}
void sort_time(Customer *C)
{
Customer *q=(Customer*)malloc(sizeof(Customer)),*p=C,*t;
Customer *temp=(Customer*)malloc(sizeof(Customer));
change_timetype1(q);
int a,b,num1=0,num2=0;
while(num1
t=p;
a=(*p).arrive_time+(*p).wait_time-(*q).arrive_time;
b=(*t).arrive_time+(*t).wait_time-(*q).arrive_time;
while(num2
if(a>b)
{
*temp=*p;
*p=*t;
*t=*temp;
}
num2++;
t++;
if(num2
}
index2--;
num2=0;
num1++;
p++;
}
index2=index1;
num2=0;num1=0;p=C;
printf("上饼顺序为:");
while(num1
printf("%s ",(*p).name);
p++;
num1++;
}
printf("\n");
}
void main()
{
FILE *sp;
sp=freopen("in.txt","r",stdin);
Customer customer[maxnumber];
Customer *p=customer;
int Operate,i;
while(1)
{
printf("1.输入顾客信息 2.输出所有顾客信息 3.输出所有的成员 4.输出上饼顺序 \n");
scanf("%d",&Operate);
switch(Operate)
{
case 1:input_customer_information(p);break;
case 2: for(i=0;i<10;i++)
printf("******");
printf("\n");
printf(" 顾客名字 愿意等待时间 到达时间 \n"); putout_onecustomer(p);break;
case 3:putout_all(p);
for( i=0;i<10;i++)
printf("******");
printf("\n"); break;
case 4: sort_time(p); break;
case 0:break;
default:continue;
}
if(Operate==0)
break;
}
fclose(sp);
}
我运用的是读文件操作,你也可以手动输入,注释掉读文件操作即可,这是运行结果,你要的功能都实现了。还望采纳哦!