#include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct stu{ int num; int mark; struct stu *next; }; struct stu *creat(int a) { int i; struct stu *head; struct stu *p; struct stu *q; head=(struct stu *)malloc(sizeof(struct stu)); head->next=NULL; q=head; for(i=0;i<a;i++) { p=(struct stu *)malloc(sizeof(struct stu)); scanf("%d %d",&p->num,&p->mark); p->next=NULL; q->next=p->next; q->next=p; q=p; } return head; } struct stu *rough(struct stu *p1,struct stu *p2) { struct stu *p=p1; while(p1->next!=NULL) p1=p1->next; p1->next=p2->next; return p; } void sort(struct stu *h) { int t; struct stu *q; struct stu *r; struct stu *s; q=h->next; r=h->next; s=r; while(r->next!=NULL) { while(s!=NULL) { if(q->num>s->num) q=s; s=s->next; } t=r->num; r->num=q->num; q->num=t; t=r->mark; r->mark=q->mark; q->mark=t; r=r->next; q=r; s=r; } } int main() { int n,m; scanf("%d%d",&n,&m); struct stu* x=creat(n); struct stu* y=creat(m); struct stu* p=rough(x,y); sort(p); p=p->next; while(p!=NULL) { printf("%d %d\n",p->num,p->mark); p=p->next; } return 0; } |
Double click to view unformatted code.