Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
85841 彭士宝 18岁生日 Python3 Wrong Answer 59 MS 5528 KB 710 2024-07-20 20:20:42

Tests(0/1):


Code:

from datetime import datetime, timedelta def calculate_days(birthdate_str): birthdate = datetime.strptime(birthdate_str, '%Y-%m-%d') # 计算18岁生日 eighteenth_birthday = birthdate.replace(year=birthdate.year + 18) # 如果18岁生日在2月29日,并且出生年份不是闰年,那么没有18岁生日 if (birthdate.day == 29 and birthdate.month == 2 and eighteenth_birthday.month != 2): return -1 # 计算天数差 days_diff = (eighteenth_birthday - birthdate).days return days_diff # 读取输入 T = int(input()) dates = [input() for _ in range(T)] # 计算并输出结果 for date in dates: print(calculate_days(date))


Run Info:

------Input------
11 1989-11-26 1962-12-02 1963-03-27 1990-03-31 1900-02-28 2000-02-29 2008-08-08 1995-02-28 2012-02-29 2020-02-28 1982-03-01
------Answer-----
6574 6575 6575 6575 6574 -1 6574 6575 -1 6575 6575
------Your output-----
6574 6575 6575 6575 6574