201509-2 日期计算

实现

#include <cstdio>

bool is_leap_year_leap_month(int year,int month) {
    if (month == 2 
    && ((year % 400 == 0) 
       || (year % 100 != 0 && year % 4 == 0))) {
        return true;
    } else {
        return false;
    }
}

int month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
    int year, cnt_day;

    scanf("%d%d",&year,&cnt_day);

    int day = 0;
    for (int i = 0;i < 12;++i) {
        day += month_days[i];
        int month_day = month_days[i];
        if (is_leap_year_leap_month(year,i+1)) {
            day+=1;
            month_day+=1;
        }
        if (cnt_day <= day) {
            printf("%d\n%d",i+1,month_day - (day - cnt_day));
            break;
        }
    }
    
}
posted @ 2020-08-29 09:12  amonqsq  阅读(150)  评论(0编辑  收藏  举报