๊ธ€ ์ž‘์„ฑ์ž: ํƒ์‹œ ์šด์ „์‚ฌ
๋ฐ˜์‘ํ˜•

๐Ÿ” ์‹œ์ € ์•”ํ˜ธ

์–ด๋–ค ๋ฌธ์žฅ์˜ ๊ฐ ์•ŒํŒŒ๋ฒณ์„ ์ผ์ •ํ•œ ๊ฑฐ๋ฆฌ๋งŒํผ ๋ฐ€์–ด์„œ ๋‹ค๋ฅธ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ๋ฐ”๊พธ๋Š” ์•”ํ˜ธํ™” ๋ฐฉ์‹์„ ์‹œ์ € ์•”ํ˜ธ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด AB๋Š” 1๋งŒํผ ๋ฐ€๋ฉด BC๊ฐ€ ๋˜๊ณ , 3๋งŒํผ ๋ฐ€๋ฉด DE๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. z๋Š” 1๋งŒํผ ๋ฐ€๋ฉด a๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด s์™€ ๊ฑฐ๋ฆฌ n์„ ์ž…๋ ฅ๋ฐ›์•„ s๋ฅผ n๋งŒํผ ๋ฏผ ์•”ํ˜ธ๋ฌธ์„ ๋งŒ๋“œ๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด ๋ณด์„ธ์š”.

์ œํ•œ ์กฐ๊ฑด

  • ๊ณต๋ฐฑ์€ ์•„๋ฌด๋ฆฌ ๋ฐ€์–ด๋„ ๊ณต๋ฐฑ์ž…๋‹ˆ๋‹ค.
  • s๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ๊ณต๋ฐฑ์œผ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
  • s์˜ ๊ธธ์ด๋Š” 8000์ดํ•˜์ž…๋‹ˆ๋‹ค.
  • n์€ 1 ์ด์ƒ, 25์ดํ•˜์ธ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค.

๐Ÿ˜ƒ ๋‚˜์˜ ํ’€์ด


1
2
3
4
5
6
7
8
9
10
11
12
13
def solution(s, n):
    upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    lower = upper.lower()
    for idx, i in enumerate(s):
        if i in upper:
            tIdx = (upper.index(i) + n)%len(upper)
            s = s[0:idx] + upper[tIdx] + s[idx+1:]
        elif i in lower:
            tIdx = (lower.index(i) + n)%len(lower)
            s = s[0:idx] + lower[tIdx] + s[idx+1:]
    print(s)
    return s

ASCII๋ฅผ ์“ธ ๊ฑธ ์ƒ๊ฐํ•ด๋ดค์ง€๋งŒ, ํŒŒ์ด์ฌ์—์„œ ASCII ์ฝ”๋“œ๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•์„ ๋ชฐ๋ž๊ธฐ ๋•Œ๋ฌธ์—, ์œ„์™€ ๊ฐ™์ด ๊ตฌํ˜„ํ–ˆ๋‹ค.


๐Ÿ˜… ์‚ฌ์šฉํ–ˆ์œผ๋ฉด ์ข‹์•˜์„ ๊ฒƒ๋“ค

  • islower(), isupper() : ํ•ด๋‹น ๋ฌธ์ž๊ฐ€ ์†Œ๋ฌธ์ž์ธ์ง€ ๋Œ€๋ฌธ์ž์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฉ”์†Œ๋“œ, ๋‚˜๋Š” if x in y๋กœ ๊ตฌํ˜„ํ–ˆ๋‹ค.\
  • chr(), ord() : ์œ ๋‹ˆ์ฝ”๋“œ์™€ ๋ฌธ์ž๊ฐ’์„ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” ๋ฉ”์†Œ๋“œ, ์œ„์˜ ์•ŒํŒŒ๋ฒณ์„ ์ง์ ‘ ์ ์ง€ ์•Š์•„๋„ ๋œ๋‹ค. 



๋ฐ˜์‘ํ˜•