본문 바로가기
python-algorithm

백준 1408 24

by 무적김두칠 2022. 11. 28.

https://www.acmicpc.net/problem/1408

 

1408번: 24

도현이는 Counter Terror Unit (CTU)에서 일하는 특수요원이다. 도현이는 모든 사건을 정확하게 24시간이 되는 순간 해결하는 것으로 유명하다. 도현이는 1시간 만에 범인을 잡을 수 있어도 잡지 않는

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def sol(start_time , end_time):
    start_hh, start_mm, start_ss = map(int, start_time.split(':'))
    end_hh, end_mm, end_ss = map(int, end_time.split(':'))
 
    total_time = (end_hh-start_hh) * 60 * 60 + (end_mm-start_mm)*60 + end_ss-start_ss
    if total_time<0:
        total_time+=60*60*24
    total_hh = int(total_time/3600)
    total_mm = int( (total_time%3600)/60)
    total_ss = (total_time%3600)%60
 
    return '%.2d:%.2d:%.2d'%(total_hh, total_mm, total_ss)
 
if __name__ == '__main__':
    start_time = input()
    end_time = input()
    print(sol(start_time,end_time))
cs

시간 관련 문제는 초로 환산해서 계산하는게 제일 편합니더
예외처리 Line 6 - 7

Time-related problems are best calculated by converting them to seconds.

Exception : Line 6 - 7

반응형

'python-algorithm' 카테고리의 다른 글

백준 11586 지영 공주님의 마법 거울  (0) 2022.11.29
백준 10801 카드게임  (0) 2022.11.28
백준 5598 카이사르 암호  (0) 2022.11.28
백준 15881 Pen Pineapple Apple Pen  (0) 2022.11.26
백준 25965 미션 도네이션  (0) 2022.11.25

댓글