描述
根据输入的日期,计算是这一年的第几天。
保证年份为4位数且日期合法。
进阶:时间复杂度:𝑂(𝑛) O(n) ,空间复杂度:𝑂(1) O(1)
输入描述:
输入一行,每行空格分割,分别是年,月,日
输出描述:
输出是这一年的第几天
示例1
输入:
2012 12 31
复制输出:
366
示例2
输入:
1982 3 4
输出:
63
本题需要注意闰年的表示,闰年是指①能被4整除的非整百年数。②如果能被100整除的年数,则必须要能整除400。遍历时应从1开始,表示从一月算起。
year,month,day=map(int,input().split())
num=0
for i in range(1,month):
if i==1 or i==3 or i==5 or i==7 or i==8 or i==10 or i==12:
num+=31
elif i==2:
if (year%4==0 and year%100!=0) or (year%100==0 and year%400==0):
num+=29
else:
num+=28
else:
num+=30
print(num+day)