暴力,构建笔画数和月份数的数组,判断闰年
将日期转化为数字进行比较,year*10000+month*100+day
#include <iostream>
using namespace std;
int date[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};//月份
int cnt[10] = {13,1,2,3,5,4,4,2,2,2}; //设置汉字对应笔画
//判断闰年
int check_year(int year)
{
return ((year%400 == 0)||((year%100!=0)&&(year%4==0))); //结果为1或者0
}
int get_day(int year,int month)
{
if(check_year(year) && month == 2)
return check_year(year) + date[month];
return date[month];
}
//判断日期,获取笔画
int get_Bihua(int date)
{
int sum = 0;
while(date)
{
sum += cnt[date%10];
date /= 10;
}
return sum;
}
int main()
{
int count = 0;//记录练习篮球的天数
for(int year = 2000;year<=2024;year++)
{
for(int month = 1;month<=12;month++)
{
for(int day = 1;day<=get_day(year,month);day++) //日期从第一天开始,天数不得超过该月的最大天数
{
int date = year*10000+month*100+day;
if(get_Bihua(date)>50 && (date <= 20240413))
count ++;
}
}
}
cout << count;
return 0;
}