题解 | #计算日期到天数转换#
计算日期到天数转换
http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
while True:
try:
year,moon,day = map(int,input().split())
a = [31,28,31,30,31,30,31,31,30,31,30,31] #所有月份对应的天数 (平年)
b = [31,29,31,30,31,30,31,31,30,31,30,31] #所有月份对应的天数 (闰年)
if(year % 4 == 0) & (year % 100 != 0) | (year % 400 == 0): #判断是否闰年
date = 0
for i in range(moon - 1):
date += b[i]
date += day
print(date)
else:
date = 0
for i in range(moon - 1):
date += a[i]
date += day
print(date)
except:
break
华为机试题解(prod.by kedao) 文章被收录于专栏
华为实习机试题解


