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

计算日期到天数转换

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

一个简单,优美的代码实现如下:

date = input().split(' ')
year = int(date[0])
month = int(date[1])
day = int(date[2])

day_list = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) :
    day_list[2] += 1    # 闰年

sum_day = 0
for i in range(month):
    sum_day += day_list[i]
sum_day += day

print(sum_day)
全部评论

相关推荐

零零幺零零幺:至少再做一个项目,然后猛投小厂,不然有点难
点赞 评论 收藏
分享
03-18 01:22
门头沟学院 Java
多多爱我我爱多多:linkedList 替换 arrayList 是怎么实现20倍提升的 好奇
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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