Python题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
import sys
year_level = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
year_leap = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
res = 0
year, month, day = map(int, input().strip().split(' '))
if year % 100 == 0:
if year % 400 == 0 and year % 4 == 0:
for i in range(month):
res += year_leap[i]
res += day
else:
for i in range(month):
res += year_level[i]
res += day
elif year % 4 == 0:
for i in range(month):
res += year_leap[i]
res += day
else:
for i in range(month):
res += year_level[i]
res += day
print(res)

查看14道真题和解析