Run ID:148125
提交时间:2026-02-09 17:09:31
#include <iostream> #include <iomanip> #include <string> using namespace std; bool isLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } int getDaysInMonth(int year, int month) { int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (isLeapYear(year) && month == 2) { return 29; } return daysInMonth[month - 1]; } int calculateDaysTo18thBirthday(int birthYear, int birthMonth, int birthDay) { int targetYear = birthYear + 18; if (birthMonth == 2 && birthDay == 29 && !isLeapYear(targetYear)) { return -1; } int totalDays = 0; for (int year = birthYear; year < targetYear; year++) { totalDays += isLeapYear(year) ? 366 : 365; } return totalDays; } int main() { int T; cin >> T; for (int i = 0; i < T; i++) { string date; cin >> date; int year, month, day; sscanf(date.c_str(), "%d-%d-%d", &year, &month, &day); int result = calculateDaysTo18thBirthday(year, month, day); cout << result << endl; } return 0; }