I solved it

Asked 2 years ago, Updated 2 years ago, 21 views

I solved it Thank you * Content Recovery

Take two years after 1583, and print out the elapsed date from January 1 of the earlier year to January 1 of the later year. It is repeated until the two years are equal.

Enter
year: 2016
Enter year: 2017
January 1st, 2016 to January 1st, 2017: 366 days
Enter year: 2016
Enter year: 2010
January 1, 2010 to January 1, 2016: 2191
Enter year: 2500
Enter year: 2000
January 1, 2000 to January 1, 2500: 182622
Enter year: 2010
Enter year: 2019
January 1, 2010 to January 1, 2019: 3287 days
Enter year: 2019
Enter year: 2019

*The leap year should be considered and datetime should not be used (Crying)"T" I don't know the chords (Crying)

python

2022-09-22 18:01

2 Answers

I don't even need a repeat. Considering the definition of leap year, This is a problem with a computational formula.

Now, you can implement this formula in Python! I just made a demo and it's calculated well according to the example given. Do it yourself!


2022-09-22 18:01

Return the repeat sentence from the early year to the slow year as a for moon Think of it as i = year If it's divided by 4, add 366 and divide by 4, but if it's divided by 100, shouldn't we show the value of 365?

fori:= fast year to slow year do
begin
  if (i mod 4) = 0 then
  begin
    if (i mod 100) = 0 then
      sumday := sumday + 365
    else sumday := sumday+ 366;
  end;
end;


2022-09-22 18:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.