我正在研究CCC J4的解
这是一个问题:
Fiona commutes to work each day. If there is no rush-hour traffic, her commute time is 2 hours. However, there is often rush-hour traffic. Specifically, rush-hour traffic occurs from 07:00 (7am) until 10:00 (10am) in the morning and 15:00 (3pm) until 19:00 (7pm) in the afternoon. During rush-hour traffic, her speed is reduced by half. She leaves either on the hour (at XX:00), 20 minutes past the hour (at XX:20), or 40 minutes past the hour (at XX:40). Given Fiona’s departure time, at what time does she arrive at work?
Input Specification
The input will be one line, which contains an expression of the form HH:MM, where HH is one of the 24 starting hours (00, 01, . . ., 23) and MM is one of the three possible departure minute times (00, 20, 40).
Output Specification
Output the time of Fiona’s arrival, in the form HH:MM.
我找到的解决方案是这样写的:
slow1s = 7*60
slow1e = 10*60
slow2s = 15*60
slow2e = 19*60
sinput = input().split(":")
startt = int(sinput[0])*60 + int(sinput[1])
D = 240
while D > 0:
if startt > slow1s and startt < slow1e:
D -= 1
elif startt > slow2s and startt < slow2e:
D -= 1
else:
D -= 2
startt += 1
if startt %10 == 9:
startt += 1
s = ""
h = startt//60%24
m = startt%60
if h < 10:
s = "0"+str(h)+":"
else:
s = str(h) + ":"
if m < 10:
s += "0"+str(m)
else:
s += str(m)
print(s)
然而,我现在不知道他/她为什么写这段代码
if startt %10 == 9:
startt += 1
我觉得它没用,但如果出发时间是14:20,它确实可以工作,因为如果删除此代码,输出是17:39,而不是17:40
目前没有回答
相关问题 更多 >
编程相关推荐