๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • ์žฅ์›์ต ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ
๐Ÿ’ป Computer Science/- Data Structure, Algorithm

[์•Œ๊ณ ๋ฆฌ์ฆ˜ PS] ๋ฐฑ์ค€ 11655๋ฒˆ ROT13 ์ž๋ฐ” ๋ฌธ์ œ ํ’€์ด

by Wonit 2021. 2. 3.

๋ฌธ์ œ

ํ•ด๋‹น ํฌ์ŠคํŒ…์€ ๋ฐฑ์ค€์˜ 11656๋ฒˆ ROT13 ์˜ ์ ‘๊ทผ๊ณผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•œ ๊ธ€ ์ž…๋‹ˆ๋‹ค.
์ •๋‹ต ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•˜์‹œ๋ ค๋ฉด solve url ์—์„œ ํ™•์ธ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ•ด์•ผ ํ•˜๋Š”์ง€๋ฅผ ๋จผ์ € ์ƒ๊ฐํ•ด๋ณด์ž.

ํ•ด๊ฒฐ๋ฒ•

์ด๋ฒˆ ๋ฌธ์ œ๋Š” ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ ๋ฌธ์ œ์ค‘ ์žฌ๋ฐŒ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๋‹ค.

 

์šฐ์„  ๋ฌธ์ œ ๋ถ„์„๋ถ€ํ„ฐ ํ•ด๋ณด์ž.


ROT13์€ ์นด์ด์‚ฌ๋ฅด ์•”ํ˜ธ์˜ ์ผ์ข…์ด๋ผ๊ณ  ํ•˜๋Š”๋ฐ, ํ•ต์‹ฌ์€ 13๊ธ€์ž ์•ž์œผ๋กœ shiftํ•˜๋ฉด ๋œ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  ๋ฌธ์ œ์—์„œ๋Š” 4๊ฐ€์ง€ ๋ฌธ์ž๊ฐ€ ๋“ค์–ด์˜ฌ ์ˆ˜ ์žˆ๋Š”๋ฐ,

 

  1. ๋Œ€๋ฌธ์ž ์•ŒํŒŒ๋ฒณ
  2. ์†Œ๋ฌธ์ž ์•ŒํŒŒ๋ฒณ
  3. ์ˆซ์ž
  4. ๊ณต๋ฐฑ

์•ŒํŒŒ๋ฒณ๋งŒ shiftํ•ด์•ผ ํ•œ๋‹ค.

์ ‘๊ทผ๋ฒ•

์กฐ๊ธˆ ๋” ์ƒ๊ฐํ•ด๋ณด๋ฉด ์‹ค์ œ๋กœ shift ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š๊ณ ๋„ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋‹ค.

 

์•ŒํŒŒ๋ฒณ ์ธ๋ฑ์Šค์— + 13์„ ๋‘ ๋ฒˆ ํ•˜๋ฉด ๋‹ค์‹œ ์›๋ž˜์˜ ๋ฌธ์ž๋กœ ๋Œ์•„์˜ค๋Š” ํŠน์„ฑ์„ ๊ฐ€์ง€๊ณ  ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ด๋ณด์ž.

 

์šฐ๋ฆฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์œผ๋กœ ๋ฌธ์ž๋ฅผ ์ฒ˜๋ฆฌํ•  ๊ฒƒ์ด๋‹ค.

 

  1. ๋ฌธ์ž์˜ ์•„์Šคํ‚ค ์ฝ”๋“œ๋ฅผ ์•ŒํŒŒ๋ฒณ ์ธ๋ฑ์Šค๋กœ ๋ณ€ํ™˜
  2. ROT13 ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰
  3. ๋ชจ๋“ˆ๋Ÿฌ 26์„ ํ†ตํ•ด ์•ŒํŒŒ๋ฒณ ์ธ๋ฑ์Šค ๋ฒ”์œ„ ์กฐ์ •
  4. ์•ŒํŒŒ๋ฒณ ์ธ๋ฑ์Šค๋ฅผ ์•„์Šคํ‚ค ์ฝ”๋“œ๋กœ ๋ณ€ํ™˜

์ด ๊ณผ์ •์„ ๊ฑฐ์น˜๋ฉด ์กฐ๊ฑด์„ ์—ฌ๋Ÿฌ๋ฒˆ ๋‚˜๋ˆ„์ง€ ์•Š์•„๋„ ํ’€ ์ˆ˜ ์žˆ๋‹ค.

์ •๋‹ต ์ฝ”๋“œ

public class Main {
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    char[] chars = br.readLine().toCharArray();

    StringBuilder sb = new StringBuilder();

    for(int i = 0; i < chars.length; i++) {
      char word = chars[i];

      if(65 <= word && word <= 90) {
        // ๋Œ€๋ฌธ์ž
        int wordIndex = (word - 'A') + 13;
        wordIndex %= 26;
        wordIndex += 'A';
        sb.append(Character.toString((char) wordIndex));
      }else if(97 <= word && word <= 122) {
        // ์†Œ๋ฌธ์ž
        int wordIndex = (word - 'a') + 13;
        wordIndex %= 26;
        wordIndex += 'a';
        sb.append(Character.toString((char) wordIndex));
      }else {
        sb.append(word);
      }
    }

    bw.write(sb.toString());
    bw.flush();
    bw.close();
  }
}

์ •๋‹ต ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•˜์‹œ๋ ค๋ฉด solve url ์—์„œ ํ™•์ธ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

๋Œ“๊ธ€