코테 기본개념/그리디

[백준 5585] 거스름돈

영민 박 2020. 5. 3. 17:50

▶ 코드

 

import sys

if __name__ == "__main__":
    N = int(sys.stdin.readline()) # N은 1000미만의 정수
    c = 0
    N = 1000 - N
    while N > 0:
      if N >= 500:
        N-=500
        c += 1
      elif N >= 100:
        N-=100
        c += 1
      elif N >= 50:
        N-=50
        c += 1
      elif N >= 10:
        N-=10
        c += 1
      elif N >= 5:
        N-=5
        c += 1
      elif N >= 1:
        N-=1
        c += 1
    print(c)