题解 | #HJ80 整型数组合并#
整型数组合并
http://www.nowcoder.com/practice/c4f11ea2c886429faf91decfaf6a310b
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmpfunc(const void* a, const void* b) {
return (*(int*)a - *(int*)b);
}
int main() {
int n1, n2;
scanf("%d", &n1);
int arr1[n1];
for (int i = 0; i < n1; i++) {
scanf("%d", &arr1[i]);
}
scanf("%d", &n2);
int arr2[n2];
for (int i = 0; i < n2; i++) {
scanf("%d", &arr2[i]);
}
int arr3[n1+n2];
memcpy(arr3, arr1, n1 * sizeof(int));
memcpy(arr3+n1, arr2, n2 * sizeof(int));
qsort(arr3, n1+n2, sizeof(int), cmpfunc);
printf("%d", arr3[0]);
for (int i = 1; i < n1+n2; i++) {
if (arr3[i] != arr3[i-1]) {
printf("%d", arr3[i]);
}
}
return 0;
}