Skip to content

Commit

Permalink
2024-04-02 거스름돈
Browse files Browse the repository at this point in the history
  • Loading branch information
suhyun113 committed Apr 3, 2024
1 parent 61dbdea commit e7bad7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions suhyun113/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

| 차시 | 날짜 | 문제유형 | 링크 | 풀이 |
|:----:|:---------:|:----:|:-----:|:----:|
| 1차시 | 2024.03.25 | 그리디 | [체육복](https://school.programmers.co.kr/learn/courses/30/lessons/42862) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/2) |
| 2차시 | 2024.03.29 | 수학 | [소수 & 팰린드롬](https://www.acmicpc.net/problem/1747) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/9) |
| 1차시 | 2024.03.25 | 그리디 | [체육복](https://school.programmers.co.kr/learn/courses/30/lessons/42862) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/2) |
| 2차시 | 2024.03.29 | 수학 | [소수 & 팰린드롬](https://www.acmicpc.net/problem/1747) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/9) |
| 3차시 | 2024.04.02 | 그리디 | [거스름돈](https://www.acmicpc.net/problem/14916) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/12) |
17 changes: 17 additions & 0 deletions suhyun113/그리디/3-suhyun113.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
n = int(input()) # 거스름돈 액수
coin_count = 0 # 동전의 개수

while True: # 무한루프
# 2원보다 5원이 더 큰 값이기 때문에, 동전의 최소 개수를 구할 때 5원부터 판별함
if n % 5 == 0: # 5로 나누어 떨어지면 5원의 개수가 최소 동전의 개수
coin_count = n // 5
break # 최소 동전의 개수이므로 바로 출력
else: # 5의 배수 아니면, 거스름돈에서 2씩 빼면서 5로 떨어지는 것을 찾음
n -= 2
coin_count += 1 # 5로 나눠떨어질 때마다 동전의 개수 증가

# 거스름돈에서 2원씩 빼다가 거스름돈이 0보다 작아지면 더 이상 거슬러줄 수 없음
if (n < 0):
print(-1)
else:
print(coin_count)

0 comments on commit e7bad7f

Please sign in to comment.