#include <iostream> using namespace std; // 判断闰年 bool isLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0; } // 计算日期 void calculateDate(int days) { int year = 1999; int monthDays[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; while (days > 365) { int daysInYear = isLeapYear(year) ? 366 : 365; if (days > daysInYear) { days -= daysInYear; year++; } } if (isLeapYear(year)) { monthDays[2] = 29; } int month = 1; while (days > monthDays[month]) { days -= monthDays[month]; month++; } cout << year << "-"; if (month < 10) { cout << "0" << month << "-"; } else { cout << month << "-"; } if (days < 10) { cout << "0" << days << endl; } else { cout << days << endl; } } int main() { int days[] = {7856}; // 这里可以添加其他整数 for (int i = 0; i < 1; i++) { cout << "整数 " << days[i] << " 对应的日期为:"; calculateDate(days[i]); } return 0; } [2024-11-28 19:22:00 | AI写代码神器 | 761点数解答]