C/C++
Программа на с++ (нужен код) пожалуйста помогите
Дана матрица N x M, состоящая из натуральных чисел. Расставить строки таким образом, чтобы элементы в первом столбце были упорядочены по убыванию. Вывести результат на экран.
#include <algorithm>
#include <iostream>
#include <random>
#include <iomanip>
using namespace std;
class Random {
public:
Random() {
random_device device;
random_generator.seed(device());
}
unsigned next(unsigned first, unsigned last) {
uniform_int_distribution<unsigned> range(first, last);
return range(random_generator);
}
private:
mt19937 random_generator;
};
unsigned* row(const size_t n) {
return new(nothrow) unsigned[n];
}
unsigned** matrix(const size_t m, const size_t n) {
auto box = new(nothrow) unsigned*[m];
for (auto i = 0U; i < m; ++i) box[i] = row(n);
return box;
}
void fill(unsigned* box, const size_t n, unsigned a, unsigned b) {
if (a > b) swap(a, b);
Random rand;
for (auto i = 0U; i < n; ++i) box[i] = rand.next(a, b);
}
void fill(unsigned** box, const size_t m, const size_t n, unsigned a, unsigned b) {
for (auto i = 0U; i < m; ++i) fill(box[i], n, a, b);
}
void print(unsigned* box, const size_t n, const streamsize w) {
for (auto i = 0U; i < n; ++i) cout << setw(w) << box[i];
}
void print(unsigned** box, const size_t m, const size_t n, const streamsize w) {
for (auto i = 0U; i < m; ++i) {
print(box[i], n, w);
cout.put('\n');
}
}
void destroy(unsigned** box, const size_t m) {
if (box) {
for (auto i = 0U; i < m; ++i) if (box[i]) delete[] box[i];
delete[] box;
}
}
size_t buffer(const char* msg) {
cout << msg;
size_t value;
cin >> value;
return value;
}
int main() {
auto m = buffer("Rows: ");
auto n = buffer("Columns: ");
auto mx = matrix(m, n);
fill(mx, m, n, 10, 99);
print(mx, m, n, 3);
cout.put('\n');
auto cpmpare = [n](unsigned* a, unsigned* b) {
return a[0] > b[0];
};
sort(mx, mx + m, cpmpare);
print(mx, m, n, 3);
cout.put('\n');
destroy(mx, m);
system("pause > nul");
}
#include <iostream>
#include <random>
#include <iomanip>
using namespace std;
class Random {
public:
Random() {
random_device device;
random_generator.seed(device());
}
unsigned next(unsigned first, unsigned last) {
uniform_int_distribution<unsigned> range(first, last);
return range(random_generator);
}
private:
mt19937 random_generator;
};
unsigned* row(const size_t n) {
return new(nothrow) unsigned[n];
}
unsigned** matrix(const size_t m, const size_t n) {
auto box = new(nothrow) unsigned*[m];
for (auto i = 0U; i < m; ++i) box[i] = row(n);
return box;
}
void fill(unsigned* box, const size_t n, unsigned a, unsigned b) {
if (a > b) swap(a, b);
Random rand;
for (auto i = 0U; i < n; ++i) box[i] = rand.next(a, b);
}
void fill(unsigned** box, const size_t m, const size_t n, unsigned a, unsigned b) {
for (auto i = 0U; i < m; ++i) fill(box[i], n, a, b);
}
void print(unsigned* box, const size_t n, const streamsize w) {
for (auto i = 0U; i < n; ++i) cout << setw(w) << box[i];
}
void print(unsigned** box, const size_t m, const size_t n, const streamsize w) {
for (auto i = 0U; i < m; ++i) {
print(box[i], n, w);
cout.put('\n');
}
}
void destroy(unsigned** box, const size_t m) {
if (box) {
for (auto i = 0U; i < m; ++i) if (box[i]) delete[] box[i];
delete[] box;
}
}
size_t buffer(const char* msg) {
cout << msg;
size_t value;
cin >> value;
return value;
}
int main() {
auto m = buffer("Rows: ");
auto n = buffer("Columns: ");
auto mx = matrix(m, n);
fill(mx, m, n, 10, 99);
print(mx, m, n, 3);
cout.put('\n');
auto cpmpare = [n](unsigned* a, unsigned* b) {
return a[0] > b[0];
};
sort(mx, mx + m, cpmpare);
print(mx, m, n, 3);
cout.put('\n');
destroy(mx, m);
system("pause > nul");
}
Сергей Феоктистов
Я конечно извиняюсь, но проще данное задание не как не сделать
Похожие вопросы
- Помогите с кодом, пожалуйста
- Задание с использование библиотечных функций С++. Нужен код. Помогите, пожалуйста.
- Нужен код на Си помогите пожалуйста
- Помогите пожалуйста! Нужен код на C++
- Пожалуйста, помогите написать программу на С++
- Срочно нужен код программы на С++
- Возникла проблема при написании кода (с++). Помогите пожалуйста.
- Помогите пожалуйста решить задачку по C++, напишите полный текст кода пожалуйста
- Пожалуйста помогите написать программу на С++
- Нужен код на Си помогите пж