#29504: Python AC解


a0962014248gg@gmail.com (李福昌)

學校 : 高雄市立前鎮高級中學
編號 : 146183
來源 : [140.114.221.145]
最後登入時間 :
2024-10-04 21:49:43
f439. 10191 - Longest Nap -- UVA10191 | From: [114.40.188.224] | 發表日期 : 2022-03-07 22:45

dc = 0
while(True):
    try:
        dc += 1
        n = int(input())
        data = [[0, 600]] + [ [sum([int(s) if idx else int(s)*60 for idx, s in enumerate(_.split(":"))]) for _ in input().split()[:2] ] for i in range(n) ] + [[1080, 0]]
        length = sorted([[data[i][0] - data[i-1][1], data[i-1][1]] for i in range(1, len(data))], key=lambda x:(x[0], -x[1]), reverse=True)
        sh, sm, dh, dm = length[0][1]//60, length[0][1]%60, length[0][0]//60, length[0][0]%60
        print(f"Day #{dc}: the longest nap starts at {sh:0>2}:{sm:0>2} and will last for " + (f"{dh} hours and " if dh else "") + f"{dm} minutes.")
    except EOFError:
        break
 
ZeroJudge Forum