結果

問題 No.256 桁の数字を入れ替え (2)
ユーザー ichibanshiboriichibanshibori
提出日時 2016-10-23 15:34:50
言語 OCaml
(5.1.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 602 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 19,568 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:34:57
合計ジャッジ時間 673 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

let dig_of_char c = int_of_char c - int_of_char '0'
let char_of_dig d = char_of_int (d + int_of_char '0')

let solve s =
  let sarr = Array.make 10 0 in
  let slen = String.length s in

  let rec make_arr idx =
    if idx < slen then (
      let dig = dig_of_char s.[idx] in
      sarr.(dig) <- sarr.(dig) + 1;
      make_arr (idx + 1)
    )
  in
  make_arr 0;
  let rec solve' idx result =
    if idx < 0 then result
    else
      let s = String.make sarr.(idx) (char_of_dig idx) in
      solve' (idx - 1) (result ^ s)
  in
  solve' 9 ""

let () =
  let n = read_line () in
  solve n |> print_endline
0