結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,124 KB
testcase_01 AC 80 ms
15,192 KB
testcase_02 AC 79 ms
15,292 KB
testcase_03 AC 81 ms
15,080 KB
testcase_04 AC 83 ms
15,132 KB
testcase_05 AC 79 ms
15,096 KB
testcase_06 AC 81 ms
15,308 KB
testcase_07 AC 83 ms
15,236 KB
testcase_08 AC 83 ms
15,152 KB
testcase_09 AC 80 ms
15,064 KB
testcase_10 AC 79 ms
15,136 KB
testcase_11 AC 79 ms
14,980 KB
testcase_12 AC 79 ms
15,304 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
    end
end

t = []

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

puts t.join
0