Algorithm/COS
[COS Pro 1급, Python] 2차 7번 : 거스름돈 구하기
JMcunst
2022. 2. 25. 10:26
728x90
문제 유형
빈칸
난이도
normal
Note
1. Greedy 알고리즘
Code
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
# 2차 7번
def solution(money):
coin = [10, 50, 100, 500, 1000, 5000, 10000, 50000]
counter = 0
idx = len(coin) - 1
while money:
counter += money // coin[idx]
money %= coin[idx]
idx -= 1
return counter
money = 2760
ret = solution(money)
print("solution 함수의 반환 값은", ret, "입니다.")
※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.
728x90