ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

11655๋ฒˆ: ROT13

์ฒซ์งธ ์ค„์— ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž, ์†Œ๋ฌธ์ž, ๊ณต๋ฐฑ, ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. S์˜ ๊ธธ์ด๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

 ROT13์€ ๋ฌธ์ž๊ฐ€ ์ž…๋ ฅ๋˜๋ฉด ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ ๊ฐ ๋ฌธ์ž๋กœ ๋ถ€ํ„ฐ 13๋ฒˆ์งธ ์ดํ›„์˜ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ์•”ํ˜ธํ™” ๋ฐฉ์‹์ด๋‹ค. ํ•ด๋‹น ์•”ํ˜ธํ™” ๋ฐฉ์‹์„ ๊ตฌํ˜„ํ•˜๋ฉด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐ ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

  • ์†Œ๋ฌธ์ž์™€ ๋Œ€๋ฌธ์ž์˜ ์ธ๋ฑ์Šค๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•œ ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ์ดˆ๊ธฐํ™” ํ•œ๋‹ค.
    • stirng ์ƒ์ˆ˜๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์ข‹๋‹ค.
  • ๋Œ€๋ฌธ์ž๋Š” ASCII์ฝ”๋“œ 65 ๋ถ€ํ„ฐ, ์†Œ๋ฌธ์ž๋Š” 97 ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋ฏ€๋กœ ์ด๋ฅผ ํ™œ์šฉํ•˜์—ฌ +13๋œ ๊ฐ’์„ ์ฐพ๋Š”๋‹ค.

 

์ฝ”๋“œ

import string

LOWER = {c: idx  for idx, c in enumerate(string.ascii_lowercase)}
UPPER = {c: idx for idx, c in enumerate(string.ascii_uppercase)}
IDX, ALPHA = 0, 1


def encrypt(c, lower):
    lst = UPPER
    factor = 65
    if lower:
        factor = 97
        lst = LOWER
    return chr(factor + ((lst[c] + 13) % 26))


def rot13(source):
    ret = ""
    for c in source:
        if c.isupper():
            ret += encrypt(c, False)
        elif c.islower():
            ret += encrypt(c, True)
        else:
            ret += c
    return ret

if __name__ == '__main__':
    print(rot13(input()))

 ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์ œ์ถœ ํ›„์— ์ƒ๊ฐํ•ด๋ณด๋‹ˆ ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ๋งŒ๋“ค ๋•Œ ์ธ๋ฑ์Šค๊ฐ€ ์•„๋‹Œ ์•„์Šคํ‚ค๋กœ ์ดˆ๊ธฐํ™” ํ–ˆ์œผ๋ฉด ๋” ๊น”๋”ํ•  ๊ฑฐ ๊ฐ™๋‹ค. ์ˆ์ฝ”๋”ฉ์˜ ๋ฐ”์ดํŠธ ์ˆ˜๊ฐ€ 51B๊ฐ€ ์žˆ์–ด์„œ ์ด๊ฑด ์–ด๋–ป๊ฒŒ ์ง ๊ฑฐ์ง€...? ํ•˜๊ณ  ๋“ค์–ด๊ฐ€ ๋ดค๋Š”๋ฐ built-in function ์ค‘์— rot13์ด ๊ตฌํ˜„๋˜์–ด ์žˆ์—ˆ๋‹ค...

 

 

codecs๋กœ ๊ตฌํ˜„ํ•œ ํ’€์ด

import codecs
print(codecs.encode(input(),"rot13"))
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€