[Algorithm/Python][SWEA] 1926번 간단한 369게임

동글이·2022년 11월 4일
0

Algorithm

목록 보기
29/33

[SWEA] 1926. 간단한 369게임

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

- 문제 접근

  • count를 세서 한번에 - 를 붙여주면 더 쉽게 풀 수 있었다!

- 내 코드

N = int(input())
result=""

for i in range(1, N+1):
    num = i
    isClap=0
    while num>10:
        if num % 10 == 3 or num % 10 == 6 or num % 10 == 9:
            result += "-"
            isClap=1
        num //= 10
    if num % 10 == 3 or num % 10 == 6 or num % 10 == 9:
        result += "-"
        isClap=1
    if isClap==0:
        result += str(i)
    result += " "

print(result)

- 더 멋진 코드

N = int(input())
clap = ['3', '6', '9']

for i in range(1, N+1):
    count = 0
    for j in str(i):
        if j in clap:
            count += 1
    if count > 0:
        i = '-' * count
    print(i, end=' ')
profile
기죽지 않는 개발자

0개의 댓글