[BOJ] 1107 리모컨

kangseonghee·2021년 8월 10일
0

Algorithm

목록 보기
10/12


풀이법 고민중

이동하려고 하는 채널을 string으로 받아 각 자리 수의 버튼이 사용가능한지 여부를 확인한다.
사용가능하면 pushed 리스트에 넣고, 사용 불가능하다면 사용가능한 버튼들과의 차의 절댓값을 파악하여 누를 버튼을 선택하려고한다.
이 후 pushed에 추가된 버튼들을 정수화 하여 이동하려고 하는 채널 N과의 차이를 계산하고 그만큼의 채널 이동을 계산한다.
최종적으로, pushed의 길이와 채널 이동 횟수를 더해주면 된다고 생각한다.

import sys

input = sys.stdin.readline
N = input() #이동하려고 하는 채널
M = int(input()) #고장난 버튼의 개수
_button = list(map(int,input().split()))
number = [0,1,2,3,4,5,6,7,8,9]
# usable = number-_button
usable = [item for item in number if item not in _button]

buttonCnt = 0 # 버튼 누른 횟수
location = 100 # 현재 위치
pushed = []

for i in range(len(N)):
    if N[i] in usable:
        pushed.append(N[i])
    else:
        selected = []
        for j in usable:
            selected[j] = abs(j-N[i])
            print(selected)
            min(selected)
        #pushed.append(min(selected))
  
pushedStr = "".join(pushed).split()
print(pushed)
#gap = int(N)-int(pushedStr)
#buttonCnt = len(pushed)+gap
if N == location :
    print(buttonCnt)

0개의 댓글