結果

問題 No.18 うーさー暗号
ユーザー deruiderui
提出日時 2016-02-06 15:08:03
言語 OCaml
(5.1.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 596 bytes
コンパイル時間 45 ms
コンパイル使用メモリ 16,896 KB
最終ジャッジ日時 2024-04-17 08:33:12
合計ジャッジ時間 446 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
File "Main.ml", line 17, characters 19-36:
17 |                    result.[ind] <- c
                        ^^^^^^^^^^^^^^^^^
Error: Syntax error: strings are immutable, there is no assignment syntax for them.
Hint: Mutable sequences of bytes are available in the Bytes module.
Hint: Did you mean to use 'Bytes.set'?

ソースコード

diff #

let length_of_alphabet = 26
let first_of_alphabet = int_of_char 'A'

let decrypt ind c =
  let amount = (ind + 1) mod length_of_alphabet in
  let c = int_of_char c in
  let slided = c - amount in
  let slided = if slided < first_of_alphabet then (int_of_char 'Z') - (first_of_alphabet - slided - 1) else slided in
  char_of_int slided

let () =
  let crypted = read_line () in
  let result = String.make (String.length crypted) ' ' in
  String.iteri (fun ind c ->
                   let c = decrypt ind c in
                   result.[ind] <- c
                 ) crypted;
  print_string result
0