“This is the 14th day of my participation in the First Challenge 2022.

I. Problem description

Blue exercises every day.

Under normal circumstances, Blue runs a kilometer a day. If it’s Monday or the beginning of the month, to motivate yourself, LAN will run 2 kilometers. If it’s Monday or the beginning of the month, Blue will also run two kilometers.

Blue has been running for a long time, from Saturday, January 1, 2000 inclusive to Thursday, October 1, 2020 inclusive. How many kilometers has Blue run during this period?

Two, the title requirements

inspection

2. It is recommended to use 10~20minCopy the code

Operating limits

  • Maximum running time: 1s
  • Maximum running memory: 128M

Third, problem analysis

The general idea is similar, with one more limitation. When you’re writing code, you need to do something special for the beginning of the month and the Monday. If the day is not the beginning of the month or the Monday, you just add one more day. Otherwise, the number of running days is increased by two days.

The core algorithm is as follows:

if(q! =1&&d! {sum+=1; } else sum+=2; // Otherwise, add two running daysCopy the code

Four, coding implementation

#include<iostream>
using namespace std;
long long int sum=0;// Define sum as an additional value
int main(a)
{
	int i,y=2000,m=1,d=1,q=6;// Initializes the definition of the year, month, and day
	int a[13] = {0.31.28.31.30.31.30.31.31.30.31.30.31};// Number of days in 12 months
	while(1)
	{
		if(y==2020&&m==10&&d==1)// The time is up
		{
			cout<<sum+2;// Output the result
			exit(0);// Exit the program
		}
		d++;// Number of days plus one
		q++;// The number of dates increases by one
		if(y%400= =0||y%4= =0&&y%100! =0)// Meet the leap year requirement
			a[2] =29;// Days become 29
		else
			a[2] =28;// Days become 28
		if(d>a[m])// The number of days is greater than the current month
		{
			d=1;// The number of days becomes 1
			m++;/ / month + +
		}
		if(m>12)// Month is greater than 12
		{
			m=1;// The month becomes 1
			y++;/ / year + +
		}
		if(q>7)// The week is greater than 7
		{
			q=1;// Change to Monday
		}
		if(q! =1&&d! =1)// Not Monday and not the first of the month
		{
			sum+=1;
		}
		else
			sum+=2;
		
	}
	return 0;
}
Copy the code

5. Output results

The output is 8879