Five weekends: Difference between revisions

m
Added code to complete the stretch task.
(New post using C++20 syntax and without using external libraries, unlike an existing post.)
m (Added code to complete the stretch task.)
Line 1,778:
 
int month_count = 0;
int blank_years = 0;
for ( int y = 1900; y <= 2100; ++y ) {
bool blank_year = true;
for ( std::chrono::month m : long_months ) {
std::chrono::year_month_day first_of_month{std::chrono::year{y}, m, std::chrono::day{1}};
Line 1,784 ⟶ 1,786:
std::cout << first_of_month.year() << " " << first_of_month.month() << std::endl;
month_count++;
blank_year = false;
}
}
if ( blank_year ) {
blank_years++;
}
}
std::cout << "Found " << month_count << " months with five Fridays, Saturdays and Sundays." << std::endl;
std::cout << "There were " << blank_years << " years with no such months." << std::endl;
}
</syntaxhighlight>
Line 1,804 ⟶ 1,811:
2100 Oct
Found 201 months with five Fridays, Saturdays and Sundays.
There were 29 years with no such months.
</pre>
 
884

edits