-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |