【2024蓝桥杯/C++/A组/艺术与篮球】

代码:

#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停下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值