#include "stdafx.h"
#define max 1000
void BubbleSort(int n, int a[])
{
int i,j,t;
for(i=0;i<n-1;i++)
for (j = 0; j < n - 1 - i; j++)
{
if (a[j] > a[j + 1])
{
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
int main()
{
int n,m,i,j,k=0,l=0,a[max],b[max],cj[max], cb[max*2], cy[max];
int flag = 0;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
scanf("%d", &m);
for (i = 0; i < m; i++)
{
scanf("%d", &b[i]);
}
for(i=0;i<n;i++) //求交
for (j = 0; j < m; j++)
{
if (a[i] == b[j])
{
cj[k++] = a[i];
}
}
BubbleSort(k, cj);
for (i = 0; i < k; i++)
printf("%d ", cj[i]);
printf("\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < k; j++)
{
if (a[i] == cj[j])
{
flag = 0;
break;
}
else
flag = 1;
}
if (flag == 1)
{
cb[l++] = a[i];
}
}
for (i = 0; i < n-k; i++)
{
cy[i] = cb[i];
}
for (i = l,j=0; i < m + n - k; i++,j++)
{
cb[i] = b[j];
}
BubbleSort(m + n - k, cb);
for (i = 0; i < m + n - k; i++)
printf("%d ", cb[i]);
printf("\n");
BubbleSort( n - k, cy);
for (i = 0; i < n-k; i++)
printf("%d ", cy[i]);
printf("\n");
return 0;
}
0.0分
0 人评分
A+B for Input-Output Practice (VI) (C++代码)浏览:445 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:1000 |
字符逆序 (C语言代码)浏览:645 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:569 |
蚂蚁感冒 (C语言代码)浏览:816 |
C二级辅导-计负均正 (C语言代码)浏览:523 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:692 |
拆分位数 (C语言代码)浏览:558 |
字符删除 (C语言代码)浏览:767 |
明明的随机数 (C语言代码)浏览:965 |