쥐수의 공부노트
백준 11047번 동전 0 본문
728x90


정답 :
let input = readLine()!.split(separator: " ").map{Int($0)!}
let n = input[0]
var total = input[1]
var coinArray : [Int] = []
var result = 0
for i in 0..<n {
let coin = Int(readLine()!)!
coinArray.append(coin)
}
for i in 0..<n {
result += total / coinArray[n-1-i]
total %= coinArray[n-i-1]
}
print(result)
가장 높은 동전의 수로 나눠서 몫만큼을 result에 저장하고, total에는 나머지를 저장
728x90
'바킹독 알고리즘 > 그리드' 카테고리의 다른 글
백준 1026번 보물 (0) | 2023.07.31 |
---|---|
백준 2217번 로프 (0) | 2023.07.27 |
백준 1931번 회의실 배정 (0) | 2023.07.27 |