jm_p_op

모의고사 해설 4. 둘만의 암호 본문

수학/알고리즘

모의고사 해설 4. 둘만의 암호

jm_p_op 2023. 4. 20. 21:24

https://school.programmers.co.kr/learn/courses/30/lessons/155652

def solve_key(skip_list, _char, index): #문자열을 다섯개더할지 일곱개더할지..
  n = 0
  _char = ord(_char)
  while True:
    _char += 1
    if _char > 122:
        _char -= 26
    if _char not in skip_list:
      n += 1
    if n == index:
      break

  return chr(_char)
def solution(s, skip, index):
    skip_list = list(map(lambda x: ord(x), skip))
    s_list = list(map(lambda x: solve_key(skip_list, x,index), s))
    answer = ''.join(s_list)
    return answer

skip_list=제외 할 문자 아스키코드열

solve_key(제외 할 문자,영단어,이동할갯수)

  • while문에서 제외할거 무시하면서 이동후 다이동하면 나오기

ord(): 아스키 코드로 바꾸기

str():아스키 코드에서 문자로 바꾸기 

 

같이 한 팀원