Kodewick
Comece a aprender →
Básico←→0 / 60

Noite de boliche

#037Básicoint &low, int &high5 min

A noite de boliche teve várias partidas, e scores guarda a pontuação de cada uma; há pelo menos uma. low_high devolve a menor e a maior por duas referências, low e high. Complete o laço: qualquer uma menor substitui low, qualquer uma maior substitui high.

Exemplos
score_range({120, 98, 145, 110})→'98 ~ 145'
score_range({77})→'77 ~ 77'
A funçãostring score_range(const vector<int> &scores)
main.cpp
#include <string>
#include <vector>
using namespace std;

void low_high(const vector<int> &scores, int &low, int &high) {
    low = scores[0];
    high = scores[0];
    for (int s : scores) {
        // seu código aqui: menor substitui low, maior substitui high
    }
}

string score_range(const vector<int> &scores) {
    int low = 0, high = 0;
    low_high(scores, low, high);
    return to_string(low) + " ~ " + to_string(high);
}
Ctrl + Enter também executa
Resultado

Executar testa os exemplos. Quando parecerem certos, Enviar.