![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8854de266e5840966460938a060a81c1.png#pic_center)
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int mouths[13] ={0,31,28,31,30,31,30,31,31,30,31,30,31};
int cnt = 5; //星期几
int ans = 0; //答案
bool check(int date) //检查当前日期是否合法
{
int year = date/10000;
int mouth = date%10000/100;
int day = date%100;
if(mouth<1||mouth>12)return false;
if(day<1)return false;
bool leap = (year%4==0&&year%100!=0)||(year%400==0); //判断是闰年还是平年
if(mouth!=2&&day>mouths[mouth])return false; //不是二月份是否合法
if(mouth==2&&day>mouths[mouth]+leap)return false; //是二月份是否合法
return true;
}
int main()
{
int start = 20000101;
for(int i=start;i<=20201001;i++)
{
if(check(i)) //检查i是否合法
{
cnt++; //判断星期几
ans++; //累计结果
int day = i%100; //计算当月天数
if(cnt%7==1||day==1)ans++; //如果是周一或者月初,结果再加1;
}
}
cout<<ans<<endl;
return 0;
}