文章

19

粉丝

47

获赞

0

访问

8.2k

头像
相隔天数 题解:C
P1825 复旦大学2019年机试
发布于2024年9月5日 20:19
阅读数 704

#include <stdio.h>
#include <math.h>

int days_in_month(int month, int year) {
    // 根据月份和年份返回每个月的天数,考虑闰年
    switch(month) {
        case 1: case 3: case 5: case 7: case 8: case 10: case 12:
            return 31;
        case 4: case 6: case 9: case 11:
            return 30;
        case 2:
            // 判断是否是闰年
            if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
                return 29;
            else
                return 28;
        default:
            return 0; // 不可能发生
    }
}

int days_from_start(int day, int month, int year) {
   ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发