123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include <stdio.h>
- int main() {
- // 读取集合A
- int A[1000];
- int num;
- int idx_A = 0;
- int i,j;
- while (scanf("%d", &num) && num != -1) {
- A[idx_A++] = num;
- }
-
- // 读取集合B
- int B[1000];
- int idx_B = 0;
- while (scanf("%d", &num) && num != -1) {
- B[idx_B++] = num;
- }
-
- // 计算差集
- int diff[1000];
- int idx_diff = 0;
- for (i = 0; i < idx_A; i++) {
- int in_B = 0;
- for (j = 0; j < idx_B; j++) {
- if (A[i] == B[j]) {
- in_B = 1;
- break;
- }
- }
- if (!in_B) {
- diff[idx_diff++] = A[i];
- }
- }
-
- // 输出差集
- for (i = 0; i < idx_diff; i++) {
- printf("%d ", diff[i]);
- }
-
- return 0;
- }
|