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

计算日期到天数转换

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

# Analyze: 闰年

def is_leap(year):
    return (year % 4 == 0 and year % 100 != 0) or year % 400 == 0
        
    
def find_day(year, month, day):
    days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    result = 0
    
    if is_leap(year): 
        days[1] = 29
    
    for i in range(month-1):
        result += days[i]    
    return result + day

while True:
    try:
        year, month, day = map(int, input().split())
        result = find_day(year, month, day)
        print(result)
    except:
        break
        
全部评论

相关推荐

牛油果甜奶昔:别的先不说,牛客还能内推护士?
点赞 评论 收藏
分享
迷茫的大四🐶:我不许你接受,我不许你启动咏鹅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务