Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <string>
- #include <time.h>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "rus");
- int n;
- cout << " Введите порядок матрицы = ";
- cin >> n;
- cout << endl;
- int **a = new int*[n];
- for (int i = 0; i < n; i++)
- {
- a[i] = new int[n];
- }
- int **b = new int*[n];
- for (int i = 0; i < n; i++)
- {
- b[i] = new int[n];
- }
- srand(time(0));
- for (int y = 0; y < n; y++)
- {
- for (int x = 0; x < n; x++)
- {
- a[y][x] = rand() % 100;
- }
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- int x_left, x_right, y_bottom, y_top;
- int maxValue = LONG_MIN;
- x_left = j;
- x_right = j + 2 > n - 1 ? n - 1 : j + 2;
- y_bottom = i;
- y_top = i - 2 < 0 ? 0 : i - 2;
- for (int i = y_bottom; i >= y_top; i--)
- {
- for (int j = x_right; j >= x_left; j--)
- {
- if (maxValue < a[i][j]) maxValue = a[i][j];
- }
- }
- b[i][j] = maxValue;
- }
- }
- cout << "\t\t" << " Исходная матрица:" << endl << endl;
- for (int y = 0; y < n; y++)
- {
- for (int x = 0; x < n; x++)
- {
- cout << "\t" << a[y][x];
- }
- cout << endl << endl;
- }
- cout << " \t\t" << " Полученнная матрица:" << endl << endl;;
- for (int y = 0; y < n; y++)
- {
- for (int x = 0; x < n; x++)
- {
- cout << "\t" << b[y][x];
- }
- cout << endl << endl;;
- }
- for (int i = 0; i < n; i++)
- {
- delete[] a[i];
- delete[] b[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement