Python(3.8+) 3行解:
while(sum(inp := [int(_) for _ in input().split()])):
t1, t2 = inp[0]*60 + [1], inp[2]*60 + [3]
print(60*24 - t1 + t2 if(t1 > t2) else t2 - t1)
Python AC解:
while(True):
inp = [int(_) for _ in input().split()]
if(not sum(inp)):break
t1, t2 = inp[0]*60 + [1], inp[2]*60 + [3]
print(60*24 - t1 + t2 if(t1 > t2) else t2 - t1)
Python 解題觀念:
1. 利用推導式取得輸入
2. 如何以 not h1+m1+h2+m2 來判斷是否結束迴圈
解題思路:
1. 取得輸入
2. 全部轉為單位分鐘t => (t = h*60 + m)
3-1. 如果t1 > t2, 則答案為 一天有幾分鐘-t1+t2 => (ans = 60*24 - t1 + t2)
3-2. 反之則為 t2 - t1