#include<stdio.h> #include<stdlib.h> struct student { int num; int score; struct student *next; } main() { int m,n,i,a,b; struct student stu1,stu2; struct student *p1,*q1,*head1,*pre,*u; struct student *p2,*q2,*head2; scanf("%d %d",&m,&n); p1=(struct student *)malloc(sizeof(struct student)); head1=p1; q1=head1; q2=head2=NULL; for(i=0;i<m;i++) { p1=(struct student *)malloc(sizeof(struct student)); scanf("%d %d",&p1->num,&p1->score); q1->next=p1; q1=p1; } for(i=0;i<n;i++) { p2=(struct student *)malloc(sizeof(struct student)); scanf("%d %d",&p2->num,&p2->score); if(q2==NULL) { head2=p2; q2=head2; } else { q2->next=p2; q2=p2; } } q2->next=NULL; p1->next=head2; while(head1->next!=NULL) { pre=head1; p1=pre->next; while(p1->next!=NULL) { if(p1->next->num<pre->next->num) pre=p1; p1=p1->next; } printf("%d %d\n",pre->next->num,pre->next->score); u=pre->next; pre->next=u->next; free(u); } free(head1); } |
Double click to view unformatted code.