結果

問題 No.227 簡単ポーカー
ユーザー ichibanshiboriichibanshibori
提出日時 2016-12-22 12:37:14
言語 OCaml
(5.1.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,064 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 18,248 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-30 07:02:08
合計ジャッジ時間 1,314 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let group_by cmp lst =
  let rec group_by' lst result =
    match lst with
    | [] -> result
    | x::xs ->
      let value = cmp x in
      let lst1, lst2 = List.partition (fun v -> value = cmp v) lst in
      group_by' lst2 ((value, lst1)::result)
  in
  group_by' lst []

let list_max_by f lst =
  let rec list_max_by' lst result =
    match lst with
    | [] -> result
    | x::xs ->
      let v = f x in
      let result = max result v in
      list_max_by' xs result
  in
  if (List.length lst) <= 0 then failwith "list_max_by"
  else list_max_by' (List.tl lst) (f (List.hd lst))



let solve a_lst =
  let g_lst = group_by (fun a -> a) a_lst in
  let g_cnt = List.length g_lst
  and max_cnt = List.map (fun (_, l) -> List.length l) g_lst |>
                list_max_by (fun a -> a)
  in
  match g_cnt, max_cnt with
  | 4, 2 -> "ONE PAIR"
  | 3, 2 -> "TWO PAIR"
  | 3, 3 -> "THREE CARD"
  | 2, 3 -> "FULL HOUSE"
  | _, _ -> "NO HAND"

let () =
  let a_lst = read_line () |>
              Str.split (Str.regexp_string " ")
  in
  solve a_lst |> print_endline
0