有两个数组a和b,把a出现在b中的元素删除,且a自己里面重复的元素也删除。
#include "stdafx.h"
int a[] = { 1,2,3,4,5,6,6,5,9,1,2 };
int b[] = {5,6};
int LEN = sizeof(a) / sizeof(a[0]);
void yiwei(int* a,int b) {
for (int i = b;i < LEN ;i++) {
a[i] = a[i + 1];
}
}
int main()
{
for (int i = 0;i < LEN;i++) {
printf("%d\t",a[i] );
}
printf("\n");
for (int i = 0;i < LEN;i++) {
for (int j = i+1;j < LEN;j++) {
if (a[i] == a[j]) {
yiwei(a, j);
LEN--;
}
}
}
for (int i = 0;i < LEN;i++) {
for (int j = 0;j < 2;j++) {
if (a[i] == b[j]) {
yiwei(a, i);
LEN--;
}
}
}
for (int i = 0;i < LEN;i++) {
printf("%d\t", a[i]);
}
printf("\n");
printf("%d", LEN);
getchar();
return 0;
}