Natural selection on average

Given a list of numbers, we say that an element is weak on average if it
is smaller than the average of the previous numbers. We consider that,
if a list is not empty, the first element is not weak on average. Design
an iterative operation that, given a non empty list of double l, puts in
another list the result of extracting from l the weak elements on
average. Use the following specification:

    void seleccio(const list<double>& l, list<double>& sel)
    /* Pre: l is not empty, sol is empty */
    /* Post: sel is the result of extracting from l the elements weak on average */

For example, if list l is

    7  -5   5   6  -2   2   5   1  -1

then list sel must be

    7   5   6   5

and if list l is

    -7  -5   5   6  -2   2   5   1  -1

list sel must be

    -7  -5   5   6   2   5   1

Input

The input is a list of double.

Output

The output is a list like the input one but without the weak on average
elements.

Observation

You only have to submit a file that contains the function with the
header in the statement as well as any other auxiliary function that you
think necessary, without any function main. Also add the includes for
any class that you use.

Problem information

Author: Alberto Moreno (adaptador), Ramon Ferrer i Cancho (responsable)

Generation: 2026-01-27T18:52:57.770Z

© Jutge.org, 2006–2026.
https://jutge.org
