오래간만에 집합이란 개념에 대해서 접하게 된건지 아니면 생각의 속도가 느린건진 모르겠지만 1시간은 걸린 것 같다. 물론 이 방법이 최적화되거나 원하는 답이 아닐 수 있으나, 나름 맞는 듯.
1 #include <stdio.h>~
2
3 int A[] = {1, 2, 3, 4, 5, 7, 11 };
4 int B[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
5
6 int inc_A(int A_el, int * B, int m);
7 int main(int argc, char * argv)
8 {
9 int j;
10 int n = 7;
11 for (j = 0 ; j < n; j++) {
12 if(!inc_A(A[j], B, 10)) {
13 printf("A is not super B\n");
14 return 1;
15 }
16 }
17 printf("A is super B\n");
18 return 0;
19 }
20
21
22 int inc_A(int A_el, int * B, int m)
23 {
24 int i;
25 for(i = 0; i < m; i++) {
26 if(A_el == B[i]) {
27 printf("matched A_el (%d) == B[%d] (%d)\n",
28 A_el, i, B[i]);
29 return 1;
30 }
31 }
32
33 printf("A_el (%d) not included\n", A_el);
34 return 0;
35 }
~
~
댓글 없음:
댓글 쓰기