Five weekends: Difference between revisions

Line 251:
#include <algorithm>
#include <iostream>
#include <iterator>
using namespace boost::gregorian ;
 
Line 258 ⟶ 259:
 
int main( ) {
greg_month longmonths[ ] = {Jan, Mar , May , Jul , Aug , Oct , Dec } ;
Aug , Oct , Dec } ;
int monthssize = sizeof ( longmonths ) / sizeof (greg_month ) ;
typedef std::vector<date> DateVector ;
DateVector weekendmonster ;
std::vector<unsigned short> years_without_5we_months ;
for ( unsigned short i = 1900 ; i < 2101 ; i++ ) {
bool months_found = false ; //does a given year have 5 weekend months ?
for ( int j = 0 ; j < monthssize ; j++ ) {
date d ( i , longmonths[ j ] , 1 ) ;
if ( d.day_of_week( ) == Friday ) { //for the month to have 5 weekends
weekendmonster.push_back( d ) ;
if ( months_found == false )
months_found = true ;
}
}
if ( months_found == false ) {
years_without_5we_months.push_back( i ) ;
}
}
std::cout << "Between 1900 and 2100 , there are " << weekendmonster.size( )
<< " months with 5 complete weekends!\n" ;
std::cout << "TheseMonths with 5 complete weekends are:\n" ;
std::for_each( weekendmonster.begin( ) , weekendmonster.end( ) , print ) ;
std::cout << years_without_5we_months.size( ) << " years had no months with 5 complete weekends!\n" ;
std::cout << "These are:\n" ;
std::copy( years_without_5we_months.begin( ) , years_without_5we_months.end( ) ,
std::ostream_iterator<unsigned short>( std::cout , "\n" ) ) ;
std::cout << std::endl ;
return 0 ;
}</lang>
Line 278 ⟶ 293:
<pre style="height:30ex;overflow:scroll">
Between 1900 and 2100 , there are 201 months with 5 complete weekends!
Months with 5 complete weekends are:
These are:
1901-Mar
1902-Aug
Line 480 ⟶ 495:
2100-Jan
2100-Oct
29 years had no months with 5 complete weekends!
These are:
1900
1906
1917
1923
1928
1934
1945
1951
1956
1962
1973
1979
1984
1990
2001
2007
2012
2018
2029
2035
2040
2046
2057
2063
2068
2074
2085
2091
2096
</pre>
 
260

edits