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

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

#include<iostream>
using namespace std;
bool fun(int year)
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return true;
else
return false;
}
int main()
{
int week = 6;
int num = 0;
int mon[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
for (int year = 2000; year <=2020; year++)
{
if (fun(year))
mon[2] = 29;
else//因为下一年不是闰年要变回28
mon[2]=28;
for (int month = 1; month <= 12; month++)
{
for (int day = 1; day <= mon[month]; day++)
{
if (day == 1 || week == 1)
num += 2;
else
num++;
week = (week) % 7 + 1;
if (year == 2020 && month == 10 && day == 1)
{
cout << num << endl;
return 0;
}
}
}
}
return 0;
}
0 回复 0 转发 1 喜欢 1 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!