网易笔试-时钟
时钟
http://www.nowcoder.com/questionTerminal/72f3cc4658024d12bcc122c29b35394e
try:
while True:
#python 字符串为只读类型,借助helper
def helper(time, scale):
# 如果小时,分钟,秒分别大于'23'、'59'、'59',则置高位为'0'
temp = []
if time > scale:
temp = list(time)
temp[0] = '0'
return ''.join(temp)
else:
return time
T = int(input())
while T > 0:
t = input()
time = t.split(':')
res = []
res.append(helper(time[0],'23'))
res.append(helper(time[1],'59'))
res.append(helper(time[2],'59'))
print(':'.join(res))
T -= 1
except:
pass
查看17道真题和解析