[BOJ] 15087 DRM Messages
Post
취소

[BOJ] 15087 DRM Messages

문제 요약 및 풀이

15087번: DRM Messages

  • python에서 ord, chr을 잘 활용하자.
  • 단계별로 최대한 함수를 나누어 구현해보면, 더 쉽게 문제가 해결된다.

풀이 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def get_sum(s):
    return sum([ord(i) - 65 for i in s])


def rotate_chr(s, n):
    return chr((ord(s) - 65 + n) % 26 + 65)


def divide(s):
    return s[: len(s) // 2], s[len(s) // 2 :]


def rotate(s, n):
    return "".join([rotate_chr(i, n) for i in s])


def merge(a, b):
    return "".join([rotate_chr(a[i], ord(b[i]) - 65) for i in range(len(a))])


s = input()
s1, s2 = divide(s)

print(merge(rotate(s1, get_sum(s1)), rotate(s2, get_sum(s2))))
This post is licensed under CC BY 4.0 by the author.

[BOJ] 9881 Ski Course Design

[TIL] 슬랙 웹훅과 깃헙 액션을 이용해 알림 봇 만들기