题目描述
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/46ce696ee38210c68facd174419c96a7.png)
源代码
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 1000;
int monthdays[2][13] = { {0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31} };
int isleapyear(int year)
{
return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 1 : 0;
}
int main()
{
int a, b, c, y1, y2;
int weekd, d, leap;
cin >> a >> b >> c >> y1 >> y2;
int basedays = 0;
basedays = (y1 - 1850) * 365 + (y1 - 1850) / 4 - (y1 - 1850) / 100 + (y1 - 1850) / 400;
for (int i = y1; i <= y2; i++)
{
int base_weekday = 2;
leap = isleapyear(i);
int days = 0;
for (int j = 1; j < a; j++)
days += monthdays[leap][j];
base_weekday += (basedays + days) % 7;
if (base_weekday > 7)
base_weekday %= 7;
int d = 1, num = 0;
while (1)
{
if (base_weekday == c)
{
num++;
}
if (num == b) break;
base_weekday++;
if (base_weekday > 7) base_weekday = 1;
d++;
}
if (d > monthdays[leap][a])
cout << "none" << endl;
else
{
cout << i << "/";
if (a < 10) cout << "0";
cout << a << "/";
if (d < 10) cout << "0";
cout << d << endl;
}
basedays += 365 + leap;
}
return 0;
}