結果

問題 No.18 うーさー暗号
ユーザー rio-yuasario-yuasa
提出日時 2023-08-17 17:57:02
言語 Ruby
(3.3.0)
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 743 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 11,468 KB
実行使用メモリ 15,296 KB
最終ジャッジ日時 2023-08-17 17:57:05
合計ジャッジ時間 2,156 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,116 KB
testcase_01 AC 81 ms
15,104 KB
testcase_02 AC 83 ms
15,280 KB
testcase_03 AC 82 ms
15,268 KB
testcase_04 AC 78 ms
15,172 KB
testcase_05 AC 82 ms
15,256 KB
testcase_06 AC 82 ms
15,296 KB
testcase_07 AC 81 ms
15,192 KB
testcase_08 AC 81 ms
14,988 KB
testcase_09 AC 81 ms
15,252 KB
testcase_10 AC 83 ms
15,124 KB
testcase_11 AC 79 ms
15,128 KB
testcase_12 AC 80 ms
15,224 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# 入力された値を文字列で受け取る
input = gets.chomp

# char を index 前の文字に戻す
def decode(char, index)

    index =index % 26

    # 64より大きい場合はそのまま使う
    if 65 <= (char.ord - index) && (char.ord - index) <= 90 then
        (char.ord - index).chr
    # 64より小さくなる場合は、64からはみ出る分を90から引く
    elsif (char.ord - index) <= 64 then
        (26 + (char.ord - index)).chr
    else
        # とにかく65〜90の範囲になるようにすればいいんだなとは思った!むずい!
        # puts i.ord - n
        (char.ord - index).chr
    end
end

t = []

input.chars.each_with_index do |i, idx|
    t << decode(i, idx + 1)
end

puts t.join
0