結果

問題 No.405 ローマ数字の腕時計
ユーザー r6eve
提出日時 2017-08-14 14:09:25
言語 OCaml
(5.2.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 21,448 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-06 19:12:41
合計ジャッジ時間 2,849 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

let rom_to_int s =
  match s with
  | "I" -> 1 | "II" -> 2 | "III" -> 3 | "IIII" -> 4 | "V" -> 5
  | "VI" -> 6 | "VII" -> 7 | "VIII" -> 8 | "IX" -> 9 | "X" -> 10
  | "XI" -> 11 | "XII" -> 0 | _ -> assert false

let int_to_rom n =
  match n with
  | 1 -> "I" | 2 -> "II" | 3 -> "III" | 4 -> "IIII" | 5 -> "V"
  | 6 -> "VI" | 7 -> "VII" | 8 -> "VIII" | 9 -> "IX" | 10 -> "X"
  | 11 -> "XI" | 0 -> "XII" | _ -> assert false

let () =
  let s, t = Scanf.scanf "%s %d " (fun s t -> s, t) in
  let x = (rom_to_int s + t) mod 12 in
  let x = x + if x >= 0 then 0 else 12 in
  int_to_rom x |> print_endline
0