Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

김찬양의 개발일지

5일차. 둘만의 암호 본문

코딩테스트/Programmers Level 1

5일차. 둘만의 암호

자유로운영혼이다냥 2023. 11. 28. 22:16

문제

풀이과정

제한사항을 보고 ord를 씌워서 그만큼 쉬프트시킨 다음에 chr을 덧씌웠다

정답

def solution(s, skip, index):
    answer = ''
    skipstr = [ord(i) for i in skip]
    skipstr.extend([ord(i)+26 for i in skip])
    skipstr.extend([ord(i)+52 for i in skip])
    alpha = [i for i in range(97, 176)]
    for i in skipstr:
        alpha.remove(i)
    for i in s:
        num = alpha[alpha.index(ord(i))+index]
        while num > 122:
            num -= 26
        answer += chr(num)
    return answer