#include <algorithm>
#include <iostream>
#include <iomanip>
#include <random>
using namespace std;
int main() {
uniform_int_distribution<> uid(1, 5);
mt19937 gen{ random_device()() };
auto rand = [&] { return uid(gen); };
auto show = [](int x) { cout << setw(3) << x; };
int matrix[5][10];
for (auto& row : matrix) generate(begin(row), end(row), rand);
for (auto& row : matrix) {
for_each(begin(row), end(row), show);
puts("");
}
int n = 0;
for (auto i = 0U; i < size(matrix[0]); ++i) {
int x = matrix[0][i];
for (auto j = 1U; j < size(matrix); ++j) {
if (matrix[j][i] <= x) x = matrix[j][i];
else {
--n;
break;
++n;
cout << "Quantity: " << n << endl;
system("pause > nul");
Объяснение:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <random>
using namespace std;
int main() {
uniform_int_distribution<> uid(1, 5);
mt19937 gen{ random_device()() };
auto rand = [&] { return uid(gen); };
auto show = [](int x) { cout << setw(3) << x; };
int matrix[5][10];
for (auto& row : matrix) generate(begin(row), end(row), rand);
for (auto& row : matrix) {
for_each(begin(row), end(row), show);
puts("");
}
int n = 0;
for (auto i = 0U; i < size(matrix[0]); ++i) {
int x = matrix[0][i];
for (auto j = 1U; j < size(matrix); ++j) {
if (matrix[j][i] <= x) x = matrix[j][i];
else {
--n;
break;
}
}
++n;
}
cout << "Quantity: " << n << endl;
system("pause > nul");
}
Объяснение: