#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node
{char num
[20];
int month
;
int day
;
struct node
*next
;
}Node
;
void insert(Node
*head
,char *sno
,int m
,int d
);
void display(Node
*head
);
int main(void)
{Node
*head
;
head
=(Node
*)malloc(sizeof(Node
));
head
->next
= NULL;
int n
;
char sno
[20];
int month
,day
;
scanf("%d",&n
);
while(n
--)
{scanf("%s %d %d",sno
,&month
,&day
);
insert(head
,sno
,month
,day
);
}
display(head
);
system("PAUSE");
return 0;
}
void insert(Node
*head
,char *sno
,int m
,int d
)
{Node
*p
=head
->next
;
Node
*prep
=head
;
Node
*s
=(Node
*)malloc(sizeof(Node
));
strcpy(s
->num
,sno
);
s
->month
=m
;
s
->day
=d
;
while(p
!=NULL)
{if(p
->month
<s
->month
||p
->month
==s
->month
&&p
->day
<=s
->day
)
{prep
=p
;
p
=p
->next
;
}
else break;
}
s
->next
=p
;
prep
->next
=s
;
}
void display
(Node
*head
)
{Node
*p
=head
->next
;
while(p
!=NULL)
{Node
*q
=p
->next
;
if (q
&&p
->month
==q
->month
&&p
->day
==q
->day
)
{printf("%d %d %s %s ",p
->month
,p
->day
,p
->num
,q
->num
);
q
=q
->next
;
while(q
&&p
->month
==q
->month
&&p
->day
==q
->day
)
{
printf("%s ",q
->num
);
q
=q
->next
;
}
printf("\n");
p
=q
;
}
else
p
=p
->next
;
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-42228.html