Run ID:85841

提交时间:2024-07-20 20:20:42

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))