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

计算日期到天数转换

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

def leap_year(year):
    if year % 400 == 0:
        return True
    else:
        if year % 4 == 0 and year % 100 != 0:
            return True
        else:
            return False
        
days_common = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
days_leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

while True:
    try:
        year, month, day = list(map(int, input().split()))
        if leap_year(year):
            print(sum(days_leap[:month-1]) + day)
        else:
            print(sum(days_common[:month-1]) + day)
    except:
        break
全部评论

相关推荐

hso_:哈哈哈哈哈哈我没offer一样在同一道题开喷了
投递深圳同为数码等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务