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

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

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int sum=0;
    int count=0;
    for(int year=2000;year<=2020;year++)
    {
        for(int month=1;month<=12;month++)
        {
            for(int day=1;day<=31;day++)
            {
                if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
                {
                    ;
                }
                else if(month==2)
                {
                    if((year%4==0&&year%100!=0)||(year%400==0))
                    {
                        if(day>29) break;
                    }
                    else
                    {
                        if(day>28) break;
                    }
                }
                else
                {
                    if(day>30)
                    {
                        break;
                    }
                }
                count++;
                if(count%7==3||day==1)
                {
                    sum+=2;
                }
                else
                {
                    sum+=1;
                }
                if(year==2020&&month==10&&day==1)
                {
                    cout<<sum;
                    return 0;
                }
            }
        }
    }
    return 0;
}
// 1=6 2=7 3=1 4=2 5=3 6=4 7=5
0 回复 0 转发 0 喜欢 6 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!