| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 84421 | 胡海峰老师 | 18岁生日 | Python3 | Wrong Answer | 62 MS | 5524 KB | 1162 | 2024-07-16 08:57:33 |
from datetime import datetime, timedelta def days_until_18th_birthday(birthdate_str): # 将字符串日期转换为datetime对象 birthdate = datetime.strptime(birthdate_str, '%Y-%m-%d') # 计算18岁生日的日期 # 如果18岁生日已经过了,就计算下一个18岁生日的日期 target_birthday = birthdate.replace(year=birthdate.year + 18) # 如果18岁生日在2月29日,并且出生年份是闰年,但18岁生日那年不是闰年,则需要调整日期 if birthdate.month == 2 and birthdate.day == 29 and not target_birthday.month == 2 or target_birthday.day == 29: target_birthday = target_birthday.replace(day=28) # 计算到达18岁生日的天数 days_count = (target_birthday - birthdate).days # 如果天数为负数,说明没有18岁生日(比如2月29日出生,但18岁那年不是闰年) if days_count < 0: return -1 return days_count # 读取输入的测试用例数量 T = int(input()) # 对每个测试用例进行处理 for _ in range(T): birthdate_str = input().strip() print(days_until_18th_birthday(birthdate_str))
------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