#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int year;
cin >> year;
//确定当前年份1月1日是星期几
int start = 0;
for (int i = 2023; i < year; i++)
{
if (i % 4 == 0) start += 2;
else start += 1;
}
start = start % 7;
if (start == 0) start += 7;
//数组初始化为0
int c[53][8];
for (int i = 0; i < 53; i++)
for (int j = 0; j < 8; j++)
c[i][j] = 0;
//生成日期
int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (year % 4 == 0) a[2] = 29;
int p = 0, q = start;
for (int m = 1; m <= 12; m++)
{
for (int i = 1; i <= a[m]; i++)
{
c[p][q] = i;
if (q == 7)
{
q = 1;
p++;
}
else
q++;
}
}
//生成月份
int month = 1;
for (int i = 0; i < 53; i++)
for (int j = 1; j < 8; j++)
if (c[i][j] == 1)
{
c[i][0] = month;
month++;
break;
}
//输出
for (int i = 0; i < 53; i++)
{
if(c[i][0] == 0) cout << " ";
else cout << setw(2) << setfill('0') << c[i][0];
for (int j = 1; j < 8; j++)
{
if (c[i][j] != 0) cout << setw(3) << setfill(' ') << c[i][j];
else cout << " ";
}
cout << endl;
}
return 0;
}
HW03-输出指定年份的日历
最新推荐文章于 2024-09-11 15:28:58 发布