CCF-CSP题解 201503-3 节日
模拟题。
良心出题人并没有\(y_1>y_2\)的样例。注意闰年的处理。
#include <bits/stdc++.h>
using namespace std;
int dayOfMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isLunar(int year)
{
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
int calendar[210][13][32];
int main()
{
for (int year = 1850, weekday = 2; year <= 2050; year++)
{
dayOfMonth[2] = isLunar(year) ? 29 : 28;
int yyear = year - 1850;
for (int month = 1; month <= 12; month++)
{
for (int day = 1; day <= dayOfMonth[month]; day++)
{
calendar[yyear][month][day] = weekday;
weekday = weekday % 7 + 1;
}
}
}
int a, b, c, y1, y2;
scanf("%d%d%d%d%d", &a, &b, &c, &y1, &y2);
for (int year = y1; year <= y2; year++)
{
dayOfMonth[2] = isLunar(year) ? 29 : 28;
int yyear = year - 1850;
int month = a;
int cnt = 0, dday = 0;
for (int day = 1; day <= dayOfMonth[month] && cnt < b; day++)
{
if (calendar[yyear][month][day] == c)
cnt++, dday = day;
}
if (cnt == b)
printf("%04d/%02d/%02d\n", year, month, dday);
else
printf("none\n");
}
return 0;
}