题解 | #计算日期到天数转换#
计算日期到天数转换
http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
两种计算方式,datetime或者手敲
import datetime def get_date_num(date_list_1): _sum = datetime.date(date_list_1[0], date_list_1[1], date_list_1[2]) sum_3 = _sum.strftime('%j') if sum_3[0] == '0' and sum_3[1] == '0': return str(sum_3[-1:]) elif sum_3[0] == '0': return str(sum_3[-2:]) else: return str(sum_3) def get_date_own(date_list_1): run = {1: 31, 2: 29, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} ping = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} y = date_list_1[0] m = date_list_1[1] d = date_list_1[2] sum_ = 0 if 0 < m <= 12 and 0 < d <= 31: if (y % 400 == 0)&nbs***bsp;(y % 4 == 0) and (y % 100 != 0): for i in range(1, m): sum_ = sum_ + run[i] return sum_ + d else: for i in range(1, m): sum_ = sum_ + ping[i] return sum_ + d while True: try: input_res = list(map(int, input().split())) n = get_date_num(input_res) print(n) except EOFError: break