틀린 풀이
def solution(s, skip, index):
alpa = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
new = ''
for i in skip:
if i in alpa:
alpa.remove(i)
for i in s:
if i in alpa:
k = alpa.index(i)
k += index
if k > 26-len(skip):
k - (26-len(skip))
new += alpa[k]
else:
new += alpa[k]
return new
if문의 계산으로 인해서 계산과정이 하나 더 생겨서 런타임에러가 났음
맞은 풀이
def solution(s, skip, index):
alpa = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
new = ''
for i in skip:
if i in alpa:
alpa.remove(i)
for i in s:
if i in alpa:
k = alpa.index(i)
k += index
new += alpa[k % (26-len(skip))]
return new
나머지를 활용하면 된다는걸 생각하지 못했음
배운 점
어떤수가 넘어가서 다시 처음부터 된다고 하면 %나머지 연산을 기억하자.
'IT 공부 > 코딩테스트' 카테고리의 다른 글
[프로그래머스 level1] 덧칠하기 파이썬 (0) | 2023.12.09 |
---|---|
[프로그래머스 level1] 대충 만든 자판 python3 (2) | 2023.12.07 |
파이썬 약수 구하기 (0) | 2023.11.29 |
[프로그래머스 level1] 명예의 전당(1) - pyhon3 (0) | 2023.08.07 |
[프로그래머스 level1] 추억 점수 (0) | 2023.08.06 |