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

计算日期到天数转换

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

如果是整百年,需要被400整除才是闰年,不是整百年被4整除就是闰年

a = input()
b, c, d = map(int,a.split(' '))

def m(b,c,d):
    if c == 1:
        print(d)
    elif c == 2:
        print(d+31)
    elif c == 3:
        print(d + 31 + 29)
    elif c == 4:
        print(d+31+29+31)
    elif c == 5:
        print(d + 31 + 29 + 31 + 30)
    elif c == 6:
        print(d + 31 + 29 + 31 + 30 + 31)
    elif c == 7:
        print(d + 31 + 29 + 31 + 30 + 31 + 30)
    elif c == 8:
        print(d + 31 + 29 + 31 + 30 + 31 + 30 + 31)
    elif c == 9:
        print(d + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31)
    elif c == 10:
        print(d + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30)
    elif c == 11:
        print(d + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31)
    elif c == 12:
        print(d + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 +30)
def n(b,c,d):
    if c == 1:
        print(d)
    elif c == 2:
        print(d+31)
    elif c == 3:
        print(d + 31 + 28)
    elif c == 4:
        print(d+31+28+31)
    elif c == 5:
        print(d + 31 + 28 + 31 + 30)
    elif c == 6:
        print(d + 31 + 28 + 31 + 30 + 31)
    elif c == 7:
        print(d + 31 + 28 + 31 + 30 + 31 + 30)
    elif c == 8:
        print(d + 31 + 28 + 31 + 30 + 31 + 30 + 31)
    elif c == 9:
        print(d + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31)
    elif c == 10:
        print(d + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30)
    elif c == 11:
        print(d + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31)
    elif c == 12:
        print(d + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 +30)
if b %100 ==0 and b%400 == 0:
    m(b, c, d)
elif b%100 != 0 and b%4==0:
    m(b,c,d)
else:
    n(b,c,d)
全部评论

相关推荐

牛客279957775号:铁暗恋
点赞 评论 收藏
分享
11-18 09:44
Java
小白也想要offer:简历别放洋屁,搞不还还放错了,当然你投外企除外,以上纯属个人观点
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务