신원준
가입: 2017년 9월 12일 올린 글: 23
|
올려짐: 2017년10월20일 16:44 주제: 과제 4-2 테스트케이스 |
|
|
코드: |
let unwrap identifier = match identifier with
| A -> 0
| B -> 1
| C -> 2
| D -> 3
| E -> 4
let _ =
let printList lst =
print_char '[';
List.iteri (fun i -> fun (id, gifts) ->
print_char '(';
print_char (Char.chr (65 + unwrap id));
print_string ", ";
(match gifts with
| [] -> print_string "nil";
| gl -> print_char '['; List.iteri(fun j -> fun gift ->
print_string (string_of_int gift);
if (j + 1 != List.length gl) then
print_string ", ";
) gl; print_char ']');
print_string ")";
if (i + 1 != List.length lst) then
print_string ", ";
) lst;
print_char ']';
print_newline() in
printList (shoppingList [
(A, [Items [1; 2]; Common (Same (B), Same (C))]);
(B, [Common (Same (C), Items [2; 3])]);
(C, [Items [1]; Except (Same (A), [3])])]);
printList (shoppingList [
(A, [Items [1; 2; 3]; Except (Items [5; 6; 7], [6]); Common (Same (D), Same (E))]);
(B, [Common (Same (A), Same (B)); Common (Same (B), Same (C)); Except (Same (D), [9])]);
(C, [Common (Same (B), Same (C)); Except (Same (E), [1; 6]); Common (Same (A), Same (D))]);
(D, [Items [4; 5; 6; 7; 8; 9; 10]; Same (B); Same (C)]);
(E, [Except (Same (A), [3]); Items [9; 10; 11]; Common (Common (Same (B), Same (D)), Items [1; 2; 3; 4; 5; 6; 7])])]);
|
예상되는 답변.. (그냥 콘솔에 출력하게 해놨어요)
인용: |
첫번째 TC: [(A, [1, 2]), (B, [2]), (C, [1, 2]), (D, nil), (E, nil)]
얘는 문제에 주어진 예시와 동일합니다.
두번째 TC: [(A, [1, 2, 3, 4, 5, 6, 7, 9, 10, 11]), (B, [2, 4, 5, 6, 7, 8, 10, 11]), (C, [2, 4, 5, 6, 7, 9, 10, 11]), (D, [2, 4, 5, 6, 7, 8, 9, 10, 11]), (E, [1, 2, 4, 5, 6, 7, 9, 10, 11])]
A B C D E의 값이 모두 서로 다르므로 주의를 요합니다.
|
|
|