結果
| 問題 |
No.1168 Digit Sum Sequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-25 22:19:16 |
| 言語 | OCaml (5.2.1) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 435 bytes |
| コンパイル時間 | 414 ms |
| コンパイル使用メモリ | 21,576 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-09 02:01:35 |
| 合計ジャッジ時間 | 1,815 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
let () =
let rec charlist_of_string str n i =
if i = n then [] else str.[i] :: charlist_of_string str n (i+1) in
let rec sum nlst = match nlst with
| [] -> 0
| h :: t -> ((int_of_char h) - 48) + sum t in
let rec solve n i =
let s = string_of_int n in
if i > 100 then n
else solve (sum (charlist_of_string s (String.length s) 0)) (i+1) in
Scanf.scanf "%d\n" @@ fun n ->
Printf.printf "%d\n" (solve n 0)