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

计算日期到天数转换

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

import sys

year_level = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
year_leap = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

res = 0
year, month, day = map(int, input().strip().split(' '))
if year % 100 == 0:
    if year % 400 == 0 and year % 4 == 0:
        for i in range(month):
            res += year_leap[i]
        res += day
    else:
        for i in range(month):
            res += year_level[i]
        res += day
elif year % 4 == 0:
    for i in range(month):
        res += year_leap[i]
    res += day

else:
    for i in range(month):
        res += year_level[i]
    res += day
print(res)

全部评论
注意闰年的判断标准是年份可以整除100的同时还得整除400和整除4才是闰年,不能整除100的年份只需要判断是否能整除4即可
点赞 回复 分享
发布于 2024-05-16 21:07 广东

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务