'거스름돈'에 해당되는 글 1건

1. 거스름돈

만든이 : 심심한 구이

 

2. 문제정보

level.goorm.io/exam/43242/%EA%B1%B0%EC%8A%A4%EB%A6%84%EB%8F%88/quiz/1

 

구름LEVEL

코딩테스트에서 가장 높은 비중을 차지하는 알고리즘 문제를 제작하고 풀이할 수 있는 온라인 저지 서비스입니다. 기업에서 선호하는 C, C++, 파이썬(Python), 자바(Java), 자바스크립트(Javascript) 이

level.goorm.io

3. 풀이

1. 코인을 만들어 준다

# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
user_input = 1000 - int(input()) '''거스름돈'''
coin500 = 0
coin100 = 0
coin50 = 0
coin10 = 0  

2.  큰코인부터 하나씩 넣어주며 다시돌린다

# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
user_input = 1000 - int(input())
coin500 = 0
coin100 = 0
coin50 = 0
coin10 = 0

''' 이제 코인을 높은수부터 넣으며 한코인이 들어갈때마다 다시 높은수부터 코인을 넣어 작은동전을 먼저넣을것을 예방한다'''
while user_input:
	if user_input >= 500:
		user_input -= 500
		coin500 += 1
		continue
	elif user_input >= 100:
		user_input -= 100
		coin100 += 1
		continue
	elif user_input >= 50:
		user_input -= 50
		coin50 += 1
		continue
	else:
		user_input -= 10
		coin10 += 1

3. 출력을 맞쳐준다

# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
user_input = 1000 - int(input())
coin500 = 0
coin100 = 0
coin50 = 0
coin10 = 0

while user_input:
	if user_input >= 500:
		user_input -= 500
		coin500 += 1
		continue
	elif user_input >= 100:
		user_input -= 100
		coin100 += 1
		continue
	elif user_input >= 50:
		user_input -= 50
		coin50 += 1
		continue
	else:
		user_input -= 10
		coin10 += 1
''' 출력을 맞쳐준다 '''
print(coin500,end=" ")
print(coin100,end=" ")
print(coin50,end=" ")
print(coin10,end=" ")

 

 

4. 결과

좀더 깔끔하게 보이게 변경하였다

# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
user_input = 1000 - int(input())
coin = [0,0,0,0]

while user_input:
	if user_input >= 500:
		user_input -= 500
		coin[0] += 1
		continue
	elif user_input >= 100:
		user_input -= 100
		coin[1] += 1
		continue
	elif user_input >= 50:
		user_input -= 50
		coin[2] += 1
		continue
	else:
		user_input -= 10
		coin[3] += 1

for i in coin:
	print(i,end=" ")

 

'Goorm ide 코딩 문제 > Level 1' 카테고리의 다른 글

[Goorm LEVEL 1] 몫과 나머지  (0) 2021.04.13
[Goorm LEVEL 1] 16진수  (0) 2021.04.13
[Goorm LEVEL 1] Bubble Sort  (0) 2021.04.12
[Goorm LEVEL 1] 삼각형의 넓이  (0) 2021.04.12
[Goorm LEVEL 1] 공백 없애기  (0) 2021.04.12
블로그 이미지

Or71nH

,