1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
int main()
{
std::array<std::pair<int, int>, 10> pancakes =
{{{6, 1}, {2, 2}, {8, 3}, {9, 4}, {4, 5},
{1, 6}, {3, 7}, {7, 8}, {15, 9}, {10, 10}}};
std::sort(pancakes.begin(), pancakes.end());
for(const auto& p: pancakes)
std::cout << "Person " << std::setw(2) << p.second <<
" ate " << std::setw(2) << p.first << " cakes" << '\n';
}
|
Person 6 ate 1 cakes
Person 2 ate 2 cakes
Person 7 ate 3 cakes
Person 5 ate 4 cakes
Person 1 ate 6 cakes
Person 8 ate 7 cakes
Person 3 ate 8 cakes
Person 4 ate 9 cakes
Person 10 ate 10 cakes
Person 9 ate 15 cakes |