Advertisement
Caneq

lb3.5.8/2

Nov 21st, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <time.h>
  4. #include <iomanip>
  5. using namespace std;
  6. int main()
  7. {
  8.     setlocale(LC_ALL, "rus");
  9.     const int N_MAX = 100;
  10.     cout << "Порядок матрицы <= " << N_MAX << ". N = ";
  11.     int N;
  12.     cin >> N;
  13.     if (N > N_MAX) N = N_MAX;
  14.     else if (N < 0) N = 0;
  15.     int A[N_MAX][N_MAX] = {};
  16.     int B[N_MAX][N_MAX] = {};
  17.         srand(static_cast<int>(time(0)));
  18.         for (int i = 0; i < N; i++)
  19.             for (int j = 0; j < N; j++)
  20.                 A[i][j] = rand() % 101;
  21.     int min_value;
  22.     min_value = A[N - 1][N - 1];
  23.     for (int k = 0; k < N; k++) {
  24.         for (int i = N - 1, j = N - 1 - k; i >= 0, j < N; i--, j++) {
  25.             B[i][j] = min_value;
  26.             if (A[i][j] < min_value) {
  27.                 min_value = A[i][j];
  28.                 for (int i = N - 1, j = N - 1 - k; i >= 0, j < N; i--, j++)
  29.                     B[i][j] = min_value;
  30.             }
  31.         }
  32.     }
  33.     for (int k = 0; k < N; k++) {
  34.         for (int i = N - 2 - k, j = 0; j < N - 1 - k, i >= 0; j++, i--) {
  35.             B[i][j] = min_value;
  36.             if (A[i][j] < min_value) {
  37.                 min_value = A[i][j];
  38.                 for (int i = N - 2 - k, j = 0; j < N - 1 - k, i >= 0; j++, i--) {
  39.                     B[i][j] = min_value;
  40.                 }
  41.             }
  42.         }
  43.     }
  44.     cout << setw(2 * N) << "Исходная матрица" << endl;
  45.     for (int y = 0; y < N; y++) {
  46.         for (int x = 0; x < N; x++) {
  47.             cout << setw(4) << A[y][x];
  48.         }
  49.         cout << endl;
  50.     }
  51.     cout << setw(2 * N) << "Полученная матрица" << endl;
  52.     for (int y = 0; y < N; y++) {
  53.         for (int x = 0; x < N; x++) {
  54.             cout << setw(4) << B[y][x];
  55.         }
  56.         cout << endl;
  57.     }
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement