#include #include #include #include #include #include #include using namespace std; /* Expected output: Highscore | Fastest Team D : 37 | Team C Team C : 12 | Team B Team B : 5 | Team A */ string team_to_string(pair const& team) { ostringstream oss{}; oss << left << setw(8) << team.first << ": " << setw(4) << team.second; return oss.str(); } int main() { vector> const results { {"Team C", 12}, {"Team B", 5}, {"Team A", 0}, {"Team D", 37}, }; vector> highscore(3); partial_sort_copy(results.begin(), results.end(), highscore.begin(), highscore.end(), [](pair const& a, pair const& b) { return a.second > b.second; }); cout << left << setw(14) << "Highscore" << " | " << setw(14) << "Fastest" << endl; transform(highscore.begin(), highscore.end(), results.begin(), ostream_iterator{cout, "\n"}, [](pair const& a, pair const& b) { return team_to_string(a) + " | " + b.first; }); }