[백준/파이썬] 15080번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 15080번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
Meredith runs a taxi service called Ruber which offers rides to clients in small towns in western Pennsylvania. She wants to get every possible dime out of people who use her taxis, so her drivers charge a flat fee not per minute but per second. It’s important, therefore, to be able to determine the exact amount of elapsed time between the moment a client enters a cab until the moment they leave. Trying to write a program to do this has driven Meredith crazy (pun intended) so she’s come to you for some help.
입력 요약
Input consists of two lines: the first contains the start time and the second contains the end time for a single taxi ride. Each time is of the form hh : mm : ss, giving the hour, minute and seconds. …
출력 요약
Display the number of seconds between the two times. No cab ride will be equal to or longer than 24 hours.
코드
a,b=list(map(int,input().split(' : '))),list(map(int,input().split(' : ')))
a,b=a[0]*3600+a[1]*60+a[2],b[0]*3600+b[1]*60+b[2]
if a>b:b+=86400
print(b-a)
설명
핵심은 구현 관점에서 Meredith runs a taxi service called Ruber which offers rides to clients in small towns in western Pennsylvania. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기