結果

問題 No.18 うーさー暗号
ユーザー sjgq5302sjgq5302
提出日時 2017-08-29 01:04:26
言語 Ruby
(3.2.2)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 690 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 11,532 KB
実行使用メモリ 15,492 KB
最終ジャッジ日時 2023-09-21 12:49:42
合計ジャッジ時間 1,900 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,140 KB
testcase_01 AC 77 ms
14,992 KB
testcase_02 AC 79 ms
15,140 KB
testcase_03 AC 89 ms
15,396 KB
testcase_04 AC 80 ms
15,492 KB
testcase_05 AC 81 ms
15,292 KB
testcase_06 AC 86 ms
15,428 KB
testcase_07 AC 87 ms
15,380 KB
testcase_08 AC 87 ms
15,340 KB
testcase_09 AC 85 ms
15,472 KB
testcase_10 AC 77 ms
14,992 KB
testcase_11 AC 76 ms
15,068 KB
testcase_12 AC 83 ms
15,280 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def usa_code(character, sequence) #うーさー復号メソッド
    code = {}
    hash_v = 1

    ("A".."Z").each{|hash_k|
        code.store(hash_k, hash_v.to_i)
        hash_v += 1
    }
    
    while sequence > 26 do #A→Zを2回以上またがないために
        sequence -= 26
    end
    
    if code[character] <= sequence then #復号でA→Zに跳ぶ時
        return code.key(26 - (sequence - code[character]))
    else
        return code.key(code[character] - sequence)
    end
end

input = gets.chomp.chars.map(&:to_s) #入力文
decryption = [] #復号文

for i in 0..(input.length - 1) do
    decryption << usa_code(input[i], (i + 1))
end

puts decryption.join("")
0