結果

問題 No.423 ハムスター語初級(数詞)
ユーザー r6ever6eve
提出日時 2017-08-17 07:58:58
言語 OCaml
(5.1.0)
結果
WA  
実行時間 -
コード長 732 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 19,692 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:42:05
合計ジャッジ時間 694 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

let ham_to_int h =
  let rec ham_to_bit s lst =
    if not (String.contains_from s 1 'h') then begin
      if s = "hamu" then 1 :: lst
      else 0 :: lst
    end else
      let m = String.length s in
      if String.index_from s 1 'h' = 4 then ham_to_bit (String.sub s 4 (m - 4)) (1 :: lst)
      else ham_to_bit (String.sub s 3 (m - 3)) (0 :: lst) in
  ham_to_bit h [] |> List.fold_left (fun (i, s) n -> 2 * i, s + n * i) (1, 0) |> snd

let int_to_hum n =
  let rec int_to_bit n lst =
    if n = 0 then lst
    else int_to_bit (n / 2) (n mod 2 :: lst) in
  int_to_bit n []
  |> List.map (fun e -> if e = 1 then "hamu" else "ham")
  |> String.concat ""

let () = read_line () |> ham_to_int |> ( * ) 2 |> int_to_hum |> print_endline
0