PS (Problem Solving)/SW Expert Academy

[SWEA] 1926. 간단한 369게임 - 파이썬

캐럿노트 2023. 1. 18. 13:00

문제

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5PTeo6AHUDFAUq&categoryId=AV5PTeo6AHUDFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=1 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

설계

- n의 각 자리 마다 3, 6, 9가 포함되어있는지 확인, 개수 count

N = int(input())
numbers = ['3', '6', '9']
answer = []
for i in range(1, N+1):
    cnt = 0
    for j in range(len(str(i))):    # 각 숫자 자리수마다 numbers가 몇개 들어있는지 확인
        if str(i)[j] in numbers:
            cnt += 1
    if cnt:                         # numbers가 포함되어 있다면 개수만큼 '-' 추가
        answer.append('-' * cnt)
    else:
        answer.append(str(i))
print(*answer)