题解 | #计算日期到天数转换#

计算日期到天数转换

http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded

闰年:能被400整除 or 能被4整除且不能被100整除

def get_ans(year,month,date):
    year,month,date=int(year),int(month),int(date)
    month_date1=[31,28,31,30,31,30,31,31,30,31,30,31]
    month_date2=[31,29,31,30,31,30,31,31,30,31,30,31]
    ans=0
    if year%400==0 or ( year%4==0 and year%100!=0):
        ans+=sum(month_date2[:month-1])
        ans+=date
    else:
        ans+=sum(month_date1[:month-1])
        ans+=date
    return ans

if __name__=='__main__':
#输入一个数/字符串
    year,month,date=input().split(' ')
    print(get_ans(year,month,date))
题解-数据结构与算法 文章被收录于专栏

小菜鸟的题解

全部评论

相关推荐

4 3 评论
分享
牛客网
牛客企业服务