[백준/파이썬] 13771번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 13771번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
The Bloggs family keep getting invited to birthday parties, and they feel they must buy the person who invites them a present. The trouble is they do not have much money!
The family has come up with a strategy. Whenever they go to a shop to buy a present, they will not buy the cheapest present (that would seem mean!), so they buy the second cheapest gift they can find. Your task here is to help them quickly find the second least expensive gift in the shop.
입력 요약
Input will consist of a single scenario which contains a list of prices from a shop, each on a separate line. The first line will contain N, the number of prices (2 <= N <= 100). No price will be duplicated. …
출력 요약
Output the second lowest price on a line by itself. It must be in the same format as with the input.
코드
print('%.2f'%sorted([float(input())for _ in range(int(input()))])[1])
설명
핵심은 구현 관점에서 The Bloggs family keep getting invited to birthday parties, and they feel they must buy the person who invites them a present. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기