알고리즘/프로그래머스 문제풀이
[프로그래머스] 둘만의 암호 풀이
감자156
2023. 10. 26. 18:57
반응형
문제
https://school.programmers.co.kr/learn/courses/30/lessons/155652
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제 풀이
skip에 속하지 않은 알파벳만 따로 정리하고(diction), diction에서의 index를 딕셔너리로 따로 정리함.
이후에는 그냥 index 이후의 diction 내의 알파벳을 저장하여 풀이함.
코드
def solution(s, skip, index):
diction = [chr(i+ord('a')) for i in range(26) if chr(i+ord('a')) not in skip]
alpha = {diction[i]:i for i in range(len(diction))}
res = ''
for c in s:
res += diction[(alpha[c] + index)%len(alpha)]
return res
반응형