1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
struct draw
{
int number ;
int date ;
static constexpr std::size_t N = 6 ;
int numbers[N] ;
int supp1 ;
int supp2 ;
};
void print_averages( const std::vector<draw>& seq )
{
if( seq.empty() ) return ;
long long totals[ draw::N ] {} ; // initialise to all zeroes
for( const auto& a_draw : seq )
{
// http://en.cppreference.com/w/cpp/algorithm/transform (3)
// http://en.cppreference.com/w/cpp/utility/functional/plus
std::transform( std::begin(a_draw.numbers), std::end(a_draw.numbers),
std::begin(totals),
std::begin(totals),
std::plus<>{} ) ;
}
for( std::size_t i = 0 ; i < draw::N ; ++i )
{
std::cout << '#' << i+1 << ". total: " << std::setw(5) << totals[i]
<< " average: " << std::fixed << std::setprecision(2)
<< std::setw(7) << totals[i] / double( seq.size() ) << '\n' ;
}
}
int main()
{
const std::vector<draw> all_draws {
{ 0, 0, { 11, 12, 13, 14, 15, 16 }, 0, 0 },
{ 0, 0, { 12, 22, 33, 13, 17, 27 }, 0, 0 },
{ 0, 0, { 13, 32, 53, 11, 19, 38 }, 0, 0 },
{ 0, 0, { 14, 42, 73, 10, 21, 49 }, 0, 0 },
{ 0, 0, { 15, 52, 93, 11, 23, 60 }, 0, 0 },
{ 0, 0, { 16, 62, 73, 12, 25, 71 }, 0, 0 },
{ 0, 0, { 17, 72, 53, 13, 27, 82 }, 0, 0 },
{ 0, 0, { 18, 82, 33, 14, 29, 93 }, 0, 0 },
};
print_averages(all_draws) ;
}
|