Problem Description
给你两个集合,要求{A} + {B}.
注:同一个集合中不会有两个相同的元素.
注:同一个集合中不会有两个相同的元素.
Input
每组输入数据分为三行,第一行有两个数字n,m(0<n,m<=10000),分别表示集合A和集合B的元素个数.后两行分别表示集合A和集合B.每个元素为不超出int范围的整数,每个元素之间有一个空格隔开.
Output
针对每组数据输出一行数据,表示合并后的集合,要求从小到大输出,每个元素之间有一个空格隔开.
Sample Input
1 2 1 2 3 1 2 1 1 2
Sample Output
1 2 3 1 2#include<stdio.h> #include<malloc.h> typedef struct L { int data; struct L *next; }Lnode,*LinList; void creat_L(LinList *L) { (*L)=(LinList)malloc(sizeof(Lnode)); (*L)->next=NULL; } void print_L(LinList L) { LinList q=L; int t=0; while(q->next) { q=q->next; if(t==0) printf("%d",q->data); else printf(" %d",q->data); t++; } printf("\n"); } void InsetList(LinList L,int a) { LinList q,p; q=L; while(q->next&&q->next->data<=a) { q=q->next; if(q->data==a) return ; } p=(LinList)malloc(sizeof(Lnode)); p->data=a; p->next=q->next; q->next=p; } int main() { int n,m,a,i; LinList L; while(scanf("%d%d",&n,&m)>0) { creat_L(&L); for(i=0;i<n+m;i++) { scanf("%d",&a); InsetList(L,a); } print_L(L); } }