赞
踩
从 1970 − 01 − 01 1970-01-01 1970−01−01 的 00 : 00 : 00 00:00:00 00:00:00 (下文称为 S S S)起,每 x x x 分钟会响一次闹钟,给定时间 T T T,请问上一次响闹钟的时间是何时?
days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] def is_leap(y): return y % 400 == 0 or y % 4 == 0 and y % 100 != 0 def daysOfMonth(y, m): if m == 2: return 28 + is_leap(y) return days[m] def betweenDays(y, m, d): yy, mm, dd = 1970, 1, 1 res = 0 while yy != y: res += 365 + is_leap(yy) yy += 1 while mm != m: res += daysOfMonth(yy, mm) mm += 1 res += d - 1 return res def get(y, m, d, h, mi): res = betweenDays(y, m, d) * 24 * 60 res += h * 60 res += mi return res def nextDay(k): y, m, d, h, mi, s = 1970, 1, 1, 0, 0, 0 while k >= (365 + is_leap(y)) * 24 * 60: k -= (365 + is_leap(y)) * 24 * 60 y += 1 while k >= daysOfMonth(y, m) * 24 * 60: k -= daysOfMonth(y, m) * 24 * 60 m += 1 while k >= 24 * 60: k -= 24 * 60 d += 1 h = k // 60 k %= 60 mi = k print("%d-%02d-%02d %02d:%02d:%02d" % (y, m, d, h, mi, s)) T = int(input()) for _ in range(T): s1, s2, s3 = input().split() y, m, d = map(int, s1.split('-')) h, mi, s = map(int, s2.split(':')) x = int(s3) k = get(y, m, d, h, mi) k -= k % x nextDay(k)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。