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
|
#include <iostream>
#include <algorithm>
int main()
{
int ar[5][4] = {{2, 4, 7, 5}, {6, 3, 8, 6}, {8, 6, 5, 4}, {9, 9, 4, 5}, {1, 7, 0, 5}};
int temp[4]{};
for (size_t i = 0; i < 5; ++i)
{
for (size_t j = i + 1; j < 5; ++j)
{
if (ar[i][1] < ar[j][1])
{
std::copy(std::begin(ar[i]), std::end(ar[i]), std::begin(temp));
std::copy(std::begin(ar[j]), std::end(ar[j]), std::begin(ar[i]));
std::copy(std::begin(temp), std::end(temp), std::begin(ar[j]));
}
}
}
for (size_t i = 0; i < 5; ++i)
{
for (size_t j = 0; j < 4; ++j)
{
std::cout << ar[i][j] << " ";
}
std::cout << "\n";
}
}
|