题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
python3
#判断是不是闰年 4年1闰 百年不闰 400年再闰
def func(y):
if y%4 == 0:
if y%100 == 0:
if y%400 == 0:
return 1
else:
return 0
else:
return 1
else:
return 0
while True:
try:
y,m,d = map(int, input().split())
run = [31,29,31,30,31,30,31,31,30,31,30,31]
ping = [31,28,31,30,31,30,31,31,30,31,30,31]
res = 0
if func(y) == 1:
if m == 1:
res = d
else:
for i in range(m-1):
res += run[i]
res += d
print(res)
else:
if m == 1:
res = d
else:
for i in range(m-1):
res += ping[i]
res +=d
print(res)
except:
break