結果

問題 No.289 数字を全て足そう
ユーザー ichibanshibori
提出日時 2016-10-13 23:53:19
言語 OCaml
(5.2.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 444 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 19,692 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-08 23:52:15
合計ジャッジ時間 947 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

let c0 = int_of_char '0'
let c9 = int_of_char '9'

let solve str =
  let lstr = String.length str in
  let rec solve' idx result =
    if idx >= lstr then result
    else
      let c = int_of_char str.[idx] in
      let nextResult =
        if c0 <= c && c <= c9 then result + c - c0
        else result
      in
      solve' (idx + 1) nextResult
  in
  solve' 0 0

let () =
  let s = read_line () in
  solve s |> string_of_int |> print_endline
0