返回题解分享
讨论 / 题解分享/ 帖子详情

跑步锻炼(结果填空) - 题解

#include<bits/stdc++.h>
using namespace std;
int main(){
    int flag=0;
    int sum=0;
    int count=0;
    for (int year = 2000; year <= 2022; year++) {
        for (int month = 1; month <= 12; month++) {
            int daysInMonth = 31; // 默认每个月有31天

            // 设置不同月份的天数
            if (month == 4 || month == 6 || month == 9 || month == 11) {
                daysInMonth = 30; // 4月、6月、9月、11月有30天
            } else if (month == 2) {
                // 处理2月(闰年判断)
                if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                    daysInMonth = 29; // 闰年
                } else {
                    daysInMonth = 28; // 非闰年
                }
            }

            // 循环遍历每个月的天数
            for (int day = 1; day <= daysInMonth; day++) {
                // 处理当前日期(年、月、日)
                // 例如,你可以打印日期或存储日期
                count++;
                if ((count-1)%7 == 2||day==1) {
                    sum=sum+2;
                }else {
                    sum=sum+1;
                }
                if (year==2020&&month==10&&day==1) {
                    cout<<sum;
                    return 0;
                }
            }
        }
    }
    return 0;
}
0 回复 0 转发 0 喜欢 1 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!