| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 148093 | 李昊阳 | 18岁生日 | C++ | Wrong Answer | 0 MS | 268 KB | 1369 | 2026-02-09 16:48:55 |
#include <iostream> #include <sstream> #include <ctime> using namespace std; // 判断是否为闰年 bool isLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } int main() { int T; cin >> T; while (T--) { string dateStr; cin >> dateStr; istringstream iss(dateStr); int year, month, day; char dash1, dash2; iss >> year >> dash1 >> month >> dash2 >> day; int targetYear = year + 18; // 判断是否有18岁生日 if ((month == 2 && day == 29 &&!isLeapYear(targetYear))) { cout << -1 << endl; continue; } int days = 0; // 计算整年的天数 for (int i = year; i < targetYear; i++) { days += isLeapYear(i)? 366 : 365; } // 计算剩余不满一年的天数 struct tm birth = {0}; birth.tm_year = year - 1900; birth.tm_mon = month - 1; birth.tm_mday = day; mktime(&birth); struct tm target = {0}; target.tm_year = targetYear - 1900; target.tm_mon = month - 1; target.tm_mday = day; mktime(&target); days += difftime(mktime(&target), mktime(&birth)) / (24 * 60 * 60); cout << days << endl; } return 0; }
------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-----
13148 13149 13150 13149 13148 -1 13149 13150 -1 13150 13149