본문 바로가기
공부/코딩테스트

백준: 15080번 Every Second Counts (Python3)

by 혼밥맨 2022. 8. 6.
반응형

백준: 15080번 Every Second Counts (Python3)

Every Second Counts 성공다국어

 
시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB 1371 781 717 58.964%

문제

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. Meredith uses a 24 hour clock, with 0 : 0 : 0 representing 12 midnight and 23 : 59 : 59 representing one second before midnight. Note that the end time may have a value less than the start time value if the ride spans midnight (see the last sample test case for an example of this).

출력

Display the number of seconds between the two times. No cab ride will be equal to or longer than 24 hours.

예제 입력 1 

10 : 0 : 0
11 : 0 : 0

예제 출력 1 

3600

예제 입력 2 

13 : 30 : 52
13 : 31 : 7

예제 출력 2 

15

예제 입력 3 

23 : 0 : 0
1 : 30 : 0

예제 출력 3 

9000

답안

1
2
3
4
5
6
7
8
h1, m1, s1 = map(int, input().split(':'))
h2, m2, s2 = map(int, input().split(':'))
t1 = h1*3600 + m1*60 + s1
t2 = h2*3600 + m2*60 + s2
if t1 > t2:
    print(t2-t1+3600*24)
else:
    print(t2-t1)
cs

반응형

댓글