题解 | #计算日期到天数转换#
计算日期到天数转换
http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
import sys
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def is_leap_year(year):
return year % 400 == 0 or (year % 100 != 0 and year % 4 == 0)
for line in sys.stdin:
year, month, day = [int(x) for x in line.split()]
if is_leap_year(year):
months[1] = 29
else:
months[1] = 28
print(sum(months[:month - 1]) + day)
查看4道真题和解析