Files
python/TangDou/KaoShi/TangDou_1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

69 lines
1.7 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
/*
2015 1 4
*/
int months_1[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int months_2[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool LeapYear(int year) {
return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
}
/*
2023 1 1 --> 7
2023 7 1 --> 6
2023 7 7
2023 5 7 --->1?
*/
int main() {
// 1、是不是需要判断闰年
int year, month;
int ydxq, month_1_xq;
// 2、year年1月1日 是星期xq
cin >> year >> month >> ydxq;
cout << "S M T W T F S" << endl;
int days = 0;
if (LeapYear(year)) {
// 比如month=5,要的是5月1号的应该是1~4月份相加的和
for (int i = 1; i < month; i++) days += months_2[i];
} else {
for (int i = 1; i < month; i++) days += months_1[i];
}
// days含义days就是当前年份的第几天-1
month_1_xq = (ydxq + days) % 7;
// 是指定月份的第1天是星期几0~6
// cout << month_1_xq << endl;
// 打空格
for (int i = 1; i <= month_1_xq; i++) cout << " ";
// 打第一行的剩余日期
// 1~ 6
// 2~ 5
// 3~ 4
// 4~ 3
// 5~ 2
// 6~ 1
// 0~ 7
for (int i = 1; i <= 7 - month_1_xq; i++) printf("%-4d", i);
cout << endl;
int this_month_days = 0;
if (LeapYear(year)) {
this_month_days = months_2[month];
} else {
this_month_days = months_1[month];
}
int cnt = 0;
for (int i = 7 - month_1_xq + 1; i <= this_month_days; i++) {
cnt++;
printf("%-4d", i);
if (cnt % 7 == 0) cout << endl;
}
return 0;
}