蓝桥杯 跑步锻炼 年月日模板 goto

小蓝每天都锻炼身体。

正常情况下,小蓝每天跑 11 千米。如果某天是周一或者月初(11 日),为了激励自己,小蓝要跑 22 千米。如果同时是周一或月初,小蓝也是跑 22 千米。

小蓝跑步已经坚持了很长时间,从 20002000 年 11 月 11 日周六(含)到 20202020 年 1010 月 11 日周四(含)。请问这段时间小蓝总共跑步多少千米?

#include <stdio.h>
int main()
{
  int year,month,day;
  int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
  int ans=5,cnt=0;
  
  for(year=2000;year<=2020;year++)
  {
    if(year%4==0&&year%100!=0||year%400==0) months[2]=29;
   else months[2]=28;
      for(month=1;month<=12;month++)
      {
          for(day=1;day<=months[month];day++)
          {
          cnt++;
      ans++;
          if(ans==8)
          ans=1;
          if(ans==1||day==1) cnt++;
          
            
      if(year==2020&&month==10&&day==1) printf("%d %d",cnt,ans);
              }
      }
  }
  

  return 0;
}

用goto的话这样写

#include <stdio.h>
int main()
{
  int year,month,day;
  int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
  int ans=5,cnt=0;
  
  for(year=2000;year<=2020;year++)
  {
    if(year%4==0&&year%100!=0||year%400==0) months[2]=29;
   else months[2]=28;
      for(month=1;month<=12;month++)
      {
          for(day=1;day<=months[month];day++)
          {
          cnt++;
      ans++;
          if(ans==8)
          ans=1;
          if(ans==1||day==1) cnt++;
      if(year==2020&&month==10&&day==1) goto end;
      }
  }

      } end: 
 printf("%d",cnt);

  return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值