[백준/파이썬] 16693번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 16693번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
There’s a pizza store which serves pizza in two sizes: either a pizza slice, with area A1 and price P1, or a circular pizza, with radius R1 and price P2.
You want to maximize the amount of pizza you get per dollar. Should you pick the pizza slice or the whole pizza?
입력 요약
The first line contains two space-separated integers A1 and P1.
Similarly, the second line contains two space-separated integers R1 and P2.
It is guaranteed that all values are positive integers at most 103. …
출력 요약
If the better deal is the whole pizza, print ‘Whole pizza’ on a single line.
If it is a slice of pizza, print ‘Slice of pizza’ on a single line.
코드
import math
a,b=map(float,input().split())
c,d=map(float,input().split())
print('Slice of pizza' if a/b>c*c*math.pi/d else 'Whole pizza')
설명
핵심은 구현 관점에서 There’s a pizza store which serves pizza in two sizes: either a pizza slice, with area A1 and price P1, or a circular pizza, with radius R1 and price …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기