代码:
#include<bits/stdc++.h>
using namespace std;
int dic[] = {13, 1, 2, 3, 5, 4, 4, 2, 2, 2};
int m[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int cal(int year, int month, int day)
{
int sum = 0; //求笔画
if(month > 0 && month < 10) sum += dic[0];
if(day > 0 && day < 10) sum += dic[0];
while(year) sum += dic[year % 10], year /= 10;
while(month) sum += dic[month % 10], month /= 10;
while(day) sum += dic[day % 10], day /= 10;
return sum;
}
int run(int year, int month)
{
if(month != 2) return 0; //不是2月,不做添
if(year % 400 == 0) return 1; //添
if(year % 100 != 0 && year % 4 == 0) return 1; //添
return 0; //不添
}
int main()
{
int year = 2000;
int month = 1;
int day = 1;
int basket = 0;
int caligraphy = 0;
for(; year != 2024 || month != 4 || day != 14; day++) //日期遍历直到2024-4-13
{
if(day > 28 && day > (m[month] + run(year, month)))
{
day = 1;
month++;
}
if(month > 12)
{
month = 1;
year++;
}
if(cal(year, month, day) > 50) basket++;
else caligraphy++;
}
cout << basket << endl;
return 0;
}
注意几个点:
1.遍历条件:ABC的非,A非+B非+C非
2.YYYY-MM-DD格式,存在01-09要特殊处理
3.日期各部分不存在全零
4.为了考虑2024-4-13,需要在2024-4-14停下