# include<stdio.h> # include<stdlib.h> struct node{ int num; int score; struct node *next; }; int main(){ int M,N; scanf("%d %d",&M,&N); struct node*L=(struct node*)malloc(sizeof(struct node)); L->next=NULL; struct node*pre=NULL,*p=NULL; for(int i=1;i<=M+N;i++){ struct node*s=(struct node*)malloc(sizeof(struct node)); scanf("%d %d",&s->num,&s->score); pre=L; if(pre->next==NULL){ pre->next=s; s->next=NULL; } else{ while(pre->next!=NULL&&(s->num)> (pre->next->num)){ pre=pre->next; } s->next=pre->next; pre->next=s; } } L=L->next; while(L!=NULL){ p=L; L=L->next; printf("%d %d\n",p->num,p->score); free(p); } return 0; } |
Double click to view unformatted code.