[SW Expert Academy, SWEA 1926] 간단한 369게임 (python)
Problem Solving/SWEA

[SW Expert Academy, SWEA 1926] 간단한 369게임 (python)

728x90

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


※ SW Expert 아카데미의 문제를 무단 복제하는 것을 금지합니다.

728x90

N = int(input())

for i in range(1, N + 1):
    num = str(i) #문자열로 변환

    count = 0 #3, 6, 9의 개수
    for n in num:
        if n =='3' or n == '6' or n == '9': #문자열에서 3, 6, 9 개수 카운트
            count += 1

    if count > 0:
        print('-' * count, end='') #3, 6, 9 개수만큼 출력
    else:
        print(num, end='')
    
    print(' ', end='')

count 함수 사용

N = int(input())

for i in range(1, N + 1):
    num = str(i) #문자열로 변환

    count = 0 #3, 6, 9의 개수
    count = num.count('3') + num.count('6') + num.count('9')

    if count > 0:
        print('-' * count, end='') #3, 6, 9 개수만큼 출력
    else:
        print(num, end='')
    
    print(' ', end='')
728x90