Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
148094 杨润东 18岁生日 C++ Wrong Answer 1 MS 276 KB 1502 2026-02-09 16:49:05

Tests(0/1):


Code:

#include <iostream> using namespace std; bool isLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } int getDaysInYear(int year) { return isLeapYear(year) ? 366 : 365; } bool isValidDate(int year, int month, int day) { if (month < 1 || month > 12) return false; if (day < 1) return false; int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (isLeapYear(year) && month == 2) { return day <= 29; } return day <= daysInMonth[month - 1]; } int main() { int T; cin >> T; for (int i = 0; i < T; i++) { int year, month, day; scanf("%d-%d-%d", &year, &month, &day); // 检查出生日期有效性 if (!isValidDate(year, month, day)) { cout << "-1" << endl; continue; } int targetYear = year + 18; // 特殊情况:2月29日出生的人在非闰年没有18岁生日 if (month == 2 && day == 29 && !isLeapYear(targetYear)) { cout << "-1" << endl; continue; } // 计算18年后的日期是否有效 if (!isValidDate(targetYear, month, day)) { cout << "-1" << endl; continue; } // 计算总天数 int totalDays = 0; for (int y = year; y < targetYear; y++) { totalDays += getDaysInYear(y); } cout << totalDays << endl; } return 0; }


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 6574 6575 6574 6574 -1 6575 6575 -1 6575 6574