[백준/파이썬] 19602번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 19602번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
Barley the dog loves treats. At the end of the day he is either happy or sad depending on the number and size of treats he receives throughout the day. The treats come in three sizes: small, medium, and large. His happiness score can be measured using the following formula:
1 × S + 2 × M + 3 × L
where S is the number of small treats, M is the number of medium treats and L is the number of large treats.
If Barley’s happiness score is 10 or greater then he is happy. Otherwise, he is sad. Determine whether Barley is happy or sad at the end of the day.
입력 요약
There are three lines of input. Each line contains a non-negative integer less than 10. The first line contains the number of small treats, S, the second line contains the number of medium treats, M, and the third line contains the number of large treats, L, that Barley receives …
출력 요약
If Barley’s happiness score is 10 or greater, output happy. Otherwise, output sad.
코드
s, m, l = int(input()), int(input()), int(input())
print('sad' if s + m*2 + l*3 < 10 else 'happy')
설명
핵심은 구현 관점에서 Barley the dog loves treats. At the end of the day he is either happy or sad depending on the number and size of treats he receives throughout the day …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기