#include <stdio.h>
#include <stdlib.h>
#define ASK_OP(response) puts("INPUT O = IN Ordinary V = IN VIP Q = QUIT");response = getch();
typedef struct _cus{
int no;
char type;
int type_num;
struct _cus *next;
}customer;
int main(int argc, char *argv[])
{
customer * phead = NULL, *pcur = NULL, *ptail = NULL;
int i,j;
char ch;
ASK_OP(ch);
while(('Q' != ch) && ('q' != ch))
{
if('o' == ch || 'O' == ch)
{
if(NULL == phead)
{
if(NULL == (phead = (customer *)malloc(sizeof(customer))))return ;
phead->no = 1;
phead->type = 'o';
phead->type_num = 0;
phead->next = NULL;
pcur = phead;
}
else
{
i=0; //记录类型为 Ordingary 的个数
ptail = phead;
while(!(NULL == ptail->next))
{
if(ptail->type == 'o') i = ptail->type_num;
ptail = ptail->next;
}
if(ptail->type == 'o') i = ptail->type_num;
if(NULL == (pcur = (customer *)malloc(sizeof(customer)))) return ;
ptail->next = pcur;
pcur->no = ptail->no+1;
pcur->type = 'o';
pcur->type_num = i+1;
pcur->next = NULL;
}
printf("\n%d Ordinary %d 前面有%d人等待\n",pcur->no,pcur->type_num,pcur->no-phead->no);
}
if('v' == ch || 'V' == ch)
{
if(NULL == phead)
{
if(NULL == (phead = (customer *)malloc(sizeof(customer)))) return ;
phead->no = 1;
phead->type = 'v';
phead->type_num = 0;
phead->next = NULL;
pcur = phead;
}
else
{
i=0; //记录类型为 Vip 的个数
ptail = phead;
while(!(NULL == ptail->next))
{
if(ptail->type == 'v') i = ptail->type_num;
ptail = ptail->next;
}
if(ptail->type == 'v') i = ptail->type_num;
if(NULL == (pcur = (customer *)malloc(sizeof(customer)))) return ;
ptail->next = pcur;
pcur->no = ptail->no+1;
pcur->type = 'v';
pcur->type_num = i+1;
pcur->next = NULL;
}
printf("\n%d VIP %d 前面有%d人等待\n",pcur->no,pcur->type_num,pcur->no-phead->no);
}
ASK_OP(ch);
}
printf("\n GOOD bye");
system("PAUSE");
return 0;
}
温馨提示:答案为网友推荐,仅供参考