문제 링크: https://www.acmicpc.net/problem/1107
백준 알고리즘 기초 2/2 500에서 4번째 - 1107번 리모컨을 풀어보았다.
풀이: https://jennnn.tistory.com/60 코드를 참고했다.
C++
Python
n=int(input())
m=int(input())
arr={str(i) for i in range(10)}
if m!=0: arr-=set(input().split())
cnt=abs(100-n)
for i in range(1000000):
i=str(i)
for j in range(len(i)):
if i[j] not in arr:
break
elif j==len(i)-1:
cnt=min(cnt,abs(int(i)-n)+len(i))
print(cnt)
Java
'코테용 문제풀이 > 백준' 카테고리의 다른 글
카잉 달력 풀이 (0) | 2023.01.24 |
---|---|
테트로미노 풀이 (0) | 2023.01.24 |
날짜 계산 풀이 (0) | 2023.01.19 |
사탕 게임 풀이 (0) | 2023.01.19 |
일곱 난쟁이 풀이 (0) | 2023.01.18 |