| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 132317 | 胡海峰老师 | 今年的第几天 | C++ | Accepted | 1 MS | 268 KB | 904 | 2025-10-07 22:08:47 |
#include <iostream> using namespace std; // 判断是否为闰年 bool isLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } // 计算一年中的第几天 int dayOfYear(int year, int month, int day) { // 每个月的天数(非闰年) int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 如果是闰年,2月有29天 if (isLeapYear(year)) { daysInMonth[1] = 29; } int totalDays = 0; // 累加前几个月的天数 for (int i = 0; i < month - 1; i++) { totalDays += daysInMonth[i]; } // 加上当前月的天数 totalDays += day; return totalDays; } int main() { int year, month, day; cin >> year >> month >> day; int result = dayOfYear(year, month, day); cout << result << endl; return 0; }