본문 바로가기
파이썬알고리즘

20210706#(62) 백준 5585 거스름돈 (그리디)

by zho 2021. 7. 6.

https://www.acmicpc.net/problem/5585

 

5585번: 거스름돈

타로는 자주 JOI잡화점에서 물건을 산다. JOI잡화점에는 잔돈으로 500엔, 100엔, 50엔, 10엔, 5엔, 1엔이 충분히 있고, 언제나 거스름돈 개수가 가장 적게 잔돈을 준다. 타로가 JOI잡화점에서 물건을 사

www.acmicpc.net

N=int(input())
joi=[500,100,50,10,5,1]
count=0
N=1000-N
while N!=0:
  if N>=joi[0]:
    N-=joi[0]
    count+=1
  elif N>=joi[1]:
    while N>=joi[1]:
      N-=joi[1]
      count+=1
  elif N>=joi[2]:
    while N>=joi[2]:
      N-=joi[2]
      count+=1
  elif N>=joi[3]:
    while N>=joi[3]:
      N-=joi[3]
      count+=1
  elif N>=joi[4]:
    while N>=joi[4]:
      N-=joi[4]
      count+=1
  elif N>=joi[5]:
    while N>=joi[5]:
      N-=joi[5]
      count+=1
print(count)

 

다른 사람의 풀이

a = 1000 - int(input())
b = [500, 100, 50, 10, 5, 1]
count = 0
for i in b:
    count += a // i
    a %= i
print(count)

 

앗 ... 이런 방법이ㅠ

728x90