Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 689 Bytes

5585.md

File metadata and controls

26 lines (20 loc) · 689 Bytes
description
백준 5585번

�거스름돈 - 5585

import Foundation

// 잡화점 거스름돈
var coins: [Int] = [500, 100, 50, 10, 5, 1]

// 항상 1000원짜리를 냄
// 지불할 돈이 주어진다, 그럼 1000 - 지불할 돈을 거슬러주면 된다,
var input = Int(readLine()!)!
var realMoney = 1000 - input // 진짜 거슬러 줘야 할 돈
var count = 0 // 잔돈 개수

// coin은 coins 배열의 원소
for coin in coins {
    count += realMoney / coin // 거슬러줘야할 돈은 동전으로 나눠준다. 그럼 그 몫이 count에 들어간다.
    realMoney = realMoney % coin // realMoney (120이 되고) = 620 나누기 500
}
print(count)