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

计算日期到天数转换

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

def ptyear(mm,dd):
    year = {"1": "31", "2": "28", "3": "31", "4": "30", "5": "31", "6": "30", "7": "31", "8": "31", "9": "30","10": "31", "11": "30", "12": "31"}
    for i in range(1, int(mm)):
        dd = dd + int(year[str(i)])
    print(dd)

def ryear(mm,dd):
    year = {"1": "31", "2": "29", "3": "31", "4": "30", "5": "31", "6": "30", "7": "31", "8": "31", "9": "30","10": "31", "11": "30", "12": "31"}
    for i in range(1, int(mm)):
        dd = dd + int(year[str(i)])
    print(dd)

while True:
    try:
        year = input()
        list = year.split(" ")
        if(int(list[0])%100 == 0):
            if(int(list[0])%400 == 0):
                ryear(int(list[1]),int(list[2]))
            else:
                ptyear(int(list[1]),int(list[2]))
        elif(int(list[0])%4 == 0):
            ryear(int(list[1]),int(list[2]))
        else:
            ptyear(int(list[1]),int(list[2]))
    except:
        break
全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务