백준 5585번 python

원래벌레·2021년 12월 31일
0

그리디 알고리즘

n=int(input())
n=1000-n
result=0
while 1:
    if n==0 :
        print(result)
        break
    if n >=500 :
        temp=n//500
        result+=temp
        n-=temp*500
    elif n>=100 and n<500:
        temp=n//100
        result+=temp
        n-=temp*100
    elif n>=50 and n<100:
        temp=n//50
        result+=temp
        n-=temp*50
    elif n>=10 and n<50 :
        temp=n//10
        result+=temp
        n-=temp*10
    elif n>=5 and n<10 :
        temp=n//5
        result+=temp
        n-=temp*5
    else :
        result+=n
        n=0
profile
학습한 내용을 담은 블로그 입니다.

0개의 댓글