| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 148121 | 冯祥瑞 | 18岁生日 | C++ | Compile Error | 0 MS | 0 KB | 1440 | 2026-02-09 17:04:58 |
#include <iostream> #include <ctime> #include <sstream> #include <iomanip> // 判断是否为闰年 bool isLeapYear(int year) { if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { return true; } return false; } int calculateDays(int birthYear, int birthMonth, int birthDay) { int targetYear = birthYear + 18; int targetMonth = birthMonth; int targetDay = birthDay; if (birthMonth == 2 && birthDay == 29 &&!isLeapYear(targetYear)) { return -1; } struct std::tm birthTime = {0}; struct std::tm targetTime = {0}; birthTime.tm_year = birthYear - 1900; birthTime.tm_mon = birthMonth - 1; birthTime.tm_mday = birthDay; targetTime.tm_year = targetYear - 1900; targetTime.tm_mon = targetMonth - 1; targetTime.tm_mday = targetDay; ime_t birthSec = std::mktime(&birthTime); time_t targetSec = std::mktime(&targetTime); if (birthSec == -1 || targetSec == -1) { return -1; } double diff = std::difftime(targetSec, birthSec) / (60 * 60 * 24); return static_cast<int>(diff); } int main() { int T; cin >> T; while (T--) { int year, month, day; char dash1, dash2; cin >> year >> dash1 >> month >> dash2 >> day; int days = calculateDays(year, month, day); cout << days << endl; } return 0; }
Main.cc: In function 'int calculateDays(int, int, int)':
Main.cc:37:5: error: 'ime_t' was not declared in this scope
ime_t birthSec = std::mktime(&birthTime);
^
Main.cc:40:9: error: 'birthSec' was not declared in this scope
if (birthSec == -1 || targetSec == -1) {
^
Main.cc:44:44: error: 'birthSec' was not declared in this scope
double diff = std::difftime(targetSec, birthSec) / (60 * 60 * 24);
^
Main.cc: In function 'int main()':
Main.cc:50:5: error: 'cin' was not declared in this scope
cin >> T;
^
Main.cc:50:5: note: suggested alternative:
In file included from Main.cc:1:0:
/usr/include/c++/5/iostream:60:18: note: 'std::cin'
extern istream cin; /// Linked to standard input
^
Main.cc:56:9: error: 'cout' was not declared in this scope
cout << days << endl;
^
Main.cc:56:9: note: suggested alternative:
In file included from Main.cc:1:0:
/usr/include/c++/5/iostream:61:18: note: 'std::cout'
extern ostream cout; /// Linked to standard output
^
Main.cc:56:25: error: 'endl' was not declared in this scope
cout << days << endl;
^
Main.cc:56:25: note: suggested alternative:
In file included from /usr/include/c++/5/iostream:39:0,
from Main.cc:1:
/usr/include/c++/5/ostream:590:5: note: 'std::endl'
endl(basic_ostream<_CharT, _Traits>& __os)
^