12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #include <stdio.h>
- #define MAX_SIZE 100
- int main() {
- int num;
- int A[MAX_SIZE], B[MAX_SIZE], C[MAX_SIZE];
- int sizeA = 0, sizeB = 0, sizeC = 0;
-
- // 读取集合A
- while (scanf("%d", &num) == 1 && num != -1) {
- A[sizeA++] = num;
- }
-
- // 读取集合B
- while (scanf("%d", &num) == 1 && num != -1) {
- B[sizeB++] = num;
- }
-
- // 计算差集 A - B
- int i, j, found;
- for (i = 0; i < sizeA; i++) {
- found = 0;
- for (j = 0; j < sizeB; j++) {
- if (A[i] == B[j]) {
- found = 1;
- break;
- }
- }
- if (!found) {
- C[sizeC++] = A[i];
- }
- }
-
- // 输出差集
- for (i = 0; i < sizeC; i++) {
- if (i > 0) printf(" ");
- printf("%d", C[i]);
- }
- printf("\n");
- return 0;
- }
|