728x90
3578번: Holes
You may have seen a mechanic typewriter — such devices were widespread just 15 years ago, before computers replaced them. It is a very simple thing. You strike a key on the typewriter keyboard, the corresponding type bar rises, and the metallic letter mo
www.acmicpc.net
문제 풀이
이 문제는 주어진 입력값만큼의 구멍 갯수를 가지는 수를 출력하는 문제이다. 구멍을 하나도 가지지 않는 수의 경우, [1, 2, 3, 5, 7]의 숫자가 출력될 것이고, 구멍이 1개인 수는 [4, 6, 9, 0], 구멍이 2개인 수는 [8]이다. 이들을 적절히 조합해서 만들 수 있는 최소의 수를 출력하면 된다.
최소의 수이므로, 구멍을 하나만 가지는 수는 '4'혹은 '0'만 사용된다. 구멍을 하나도 가지지 않는 경우는 '1'만 사용될 것이다. 이를 규칙으로 만들어 코드를 작성해주었다.
정답 코드
n = int(input())
if n == 0 : print(1)
elif n == 1 : print(0)
elif n % 2 == 0 : print("8" * (n // 2))
else : print("4" + "8" * (n // 2))
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 4435 - 중간계 전쟁 [python] (0) | 2023.03.08 |
---|---|
[BOJ/백준] 4084 - Viva la Diferencia [python] (0) | 2023.03.08 |
[BOJ/백준] 3533 - Explicit Formula [python] (0) | 2023.03.07 |
[BOJ/백준] 3507 - Automated Telephone Exchange [python] (0) | 2023.03.07 |
[프로그래머스] 개인정보 수집 유효기간 [python] (0) | 2023.03.07 |