#include <iostream>
#include <time.h>
#include <vector>
using namespace std;
void print_array(int** arr, int n, int m) {
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
int** auto_input_matrix(int** arr, int n, int m) {
arr[i][j] = rand() % 200 - 100;
return arr;
void print_vector(vector<long long> vec) {
for (long long elem : vec) {
cout << elem << " ";
void print_vector(vector<int> vec) {
for (int elem : vec) {
pair<vector<long long>, vector<int>> multiplying_positive_elements_of_an_array_and_find_max_of_an_array_line_by_line(int** arr, int n, int m) {
long long multi = 0;
bool key = false;
int max = -100;
int index = 0;
vector<long long> vec_multi;
vector<int> vec_max_index;
if (arr[i][j] > max) {
max = arr[i][j];
index = j;
if (arr[i][j] > 0) {
if (!key) {
multi = 1;
key = true;
multi *= arr[i][j];
vec_max_index.push_back(index);
vec_multi.push_back(multi);
max = -100;
key = false;
return make_pair(vec_multi, vec_max_index);
int main() {
srand(time(NULL));
setlocale(LC_ALL, "Russian");
int n, m;
cout << "Введите количество строк в массиве: ";
cin >> n;
cout << "Введите количество элементов в массиве построчно: ";
cin >> m;
int** array = new int* [n];
pair<vector<long long>, vector<int>> pair_vec;
array[i] = new int[m];
array = auto_input_matrix(array, n, m);
print_array(array, n, m);
pair_vec = multiplying_positive_elements_of_an_array_and_find_max_of_an_array_line_by_line(array, n, m);
cout << "Перемножение построчно: " << endl;
print_vector(pair_vec.first);
cout << "Максимумы на индексах: " << endl;
print_vector(pair_vec.second);
delete[] array;
pair_vec.first.clear();
pair_vec.second.clear();
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <time.h>
#include <vector>
using namespace std;
void print_array(int** arr, int n, int m) {
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
int** auto_input_matrix(int** arr, int n, int m) {
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++) {
arr[i][j] = rand() % 200 - 100;
}
}
return arr;
}
void print_vector(vector<long long> vec) {
for (long long elem : vec) {
cout << elem << " ";
}
cout << endl;
}
void print_vector(vector<int> vec) {
for (int elem : vec) {
cout << elem << " ";
}
cout << endl;
}
pair<vector<long long>, vector<int>> multiplying_positive_elements_of_an_array_and_find_max_of_an_array_line_by_line(int** arr, int n, int m) {
long long multi = 0;
bool key = false;
int max = -100;
int index = 0;
vector<long long> vec_multi;
vector<int> vec_max_index;
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < m; j++) {
if (arr[i][j] > max) {
max = arr[i][j];
index = j;
}
if (arr[i][j] > 0) {
if (!key) {
multi = 1;
}
key = true;
multi *= arr[i][j];
}
}
vec_max_index.push_back(index);
vec_multi.push_back(multi);
max = -100;
key = false;
}
return make_pair(vec_multi, vec_max_index);
}
int main() {
srand(time(NULL));
setlocale(LC_ALL, "Russian");
int n, m;
cout << "Введите количество строк в массиве: ";
cin >> n;
cout << "Введите количество элементов в массиве построчно: ";
cin >> m;
int** array = new int* [n];
pair<vector<long long>, vector<int>> pair_vec;
for (size_t i = 0; i < n; i++) {
array[i] = new int[m];
}
array = auto_input_matrix(array, n, m);
print_array(array, n, m);
pair_vec = multiplying_positive_elements_of_an_array_and_find_max_of_an_array_line_by_line(array, n, m);
cout << "Перемножение построчно: " << endl;
print_vector(pair_vec.first);
cout << "Максимумы на индексах: " << endl;
print_vector(pair_vec.second);
delete[] array;
pair_vec.first.clear();
pair_vec.second.clear();
}