跑步锻炼问题

题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。小蓝每天都锻炼身体。
正常情况下,小蓝每天跑1千米。如果某天是周一或者月初(1日),为了激励自己。小蓝要跑2千米。如果同时是周一或月初,小蓝也显跑2千米。
小蓝翻步已经坚持了很长时间,从2000年1月1日周六(含)到2020年10月1日周四(含)。消问这段时间小蓝总共跑步多少千米?

代码:

#include<iostream>

#include<cstdio>

using namespace std;

int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

bool is_leap(int y)

{

 return (y%400==0||y%4==0 && y%100!=0); 

int daysOfMonth(int y,int month)

{

 if(month==2) return is_leap(y)+28;

 return days[month];

}

int main()

{

 int year=2000,month=1,day=1,w=6;

 int res=0;

 while(year!=2020 || month!=10 || day!=2)

 {

  if(day==1 || w==1) res+=2;

  else res++;

  day++;

  if(day>daysOfMonth(year,month)) 

       day=1,month++;

  if(month>12)  

       month=1,year++;

  w++;

  if(w==8) w=1;

 }

 cout<<res<<endl;

 return 0;

}
 

猜你喜欢

转载自blog.csdn.net/2302_77099705/article/details/130815006