結果

問題 No.18 うーさー暗号
ユーザー tokustokus
提出日時 2021-11-17 11:47:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 1,484 bytes
コンパイル時間 2,425 ms
コンパイル使用メモリ 75,160 KB
実行使用メモリ 49,828 KB
最終ジャッジ日時 2023-08-24 21:59:42
合計ジャッジ時間 3,914 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,208 KB
testcase_01 AC 42 ms
49,292 KB
testcase_02 AC 43 ms
49,232 KB
testcase_03 AC 44 ms
49,288 KB
testcase_04 AC 42 ms
47,200 KB
testcase_05 AC 43 ms
47,108 KB
testcase_06 AC 44 ms
49,164 KB
testcase_07 AC 45 ms
49,476 KB
testcase_08 AC 45 ms
49,828 KB
testcase_09 AC 45 ms
49,304 KB
testcase_10 AC 42 ms
49,208 KB
testcase_11 AC 42 ms
49,360 KB
testcase_12 AC 44 ms
49,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package レベル1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.stream.Stream;

class Main {
    public static void main(String[] args) {
        no18();
    }

    // No.18 うーさー暗号
    private static void no18() {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        // 入力値
        String input = "";

        char[] alphabet = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

        try {
            input = reader.readLine();
            reader.close();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }

        char[] inputs = input.toCharArray();

        StringBuilder output = new StringBuilder();

        for (int i = 0, j = 1; i < inputs.length; i++, j++) {
            if (i % 26 == 0) {
                j = 1;
            }
            for (int k = 0; k < alphabet.length; k++) {
                if (alphabet[k] == inputs[i]) {
                    if (k - j < 0) {
                        
                        output.append(alphabet[26 - j + k]);
                    } else {
                        output.append(alphabet[k - j]);
                    }
                }
            }
        }
        
        System.out.println(output.toString());
    }
}
0