본문 바로가기
Algorithm/Greedy

[백준] 5585번 거스름돈

by 등촌동 꼬북이 2020. 10. 6.

아주 쉬운 문제

 

def greedy(N):
    counter = 0
    while N > 0:
        if N % 500 == 0:
            N = N - 500
            counter += 1
        elif N % 100 == 0:
            N = N - 100
            counter += 1
        elif N % 50 == 0:
            N = N - 50
            counter += 1
        elif N % 10 == 0:
            N = N - 10
            counter += 1
        elif N % 5 == 0:
            N = N - 5
            counter += 1
        else:
            N = N - 1
            counter += 1
    return counter
print(greedy(1000 - int(input())))

'Algorithm > Greedy' 카테고리의 다른 글

[프로그래머스] 체육복  (0) 2020.10.09
[백준] 11047번 동전 0  (0) 2020.10.07
[백준] 14720번 우유 축제  (0) 2020.10.06
[백준] 10162번 전자레인지  (0) 2020.10.06
[백준] 2839번 설탕 배달  (0) 2020.09.29

댓글