Advertisement
Caneq

lb3.5.8

Nov 9th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <time.h>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     setlocale(LC_ALL, "rus");
  10.     const int N_MAX = 100;
  11.     cout << "Порядок матрицы <= " << N_MAX << ". N = ";
  12.     int N;
  13.     cin >> N;
  14.     if (N > N_MAX)
  15.         N = N_MAX;
  16.     else if (N < 0)
  17.         N = 0;
  18.     int A[N_MAX][N_MAX] = {};
  19.     int B[N_MAX][N_MAX] = {};
  20.  
  21.     enum
  22.     {
  23.         fill_in_code,
  24.         fill_rand,
  25.         fill_keyboard,
  26.     };
  27.  
  28.     cout << "Выберите способ ввода элементов массива\r\n"
  29.         << fill_in_code << " - Инициализация в коде\r\n"
  30.         << fill_rand << " - Заполнение случайными числами\r\n"
  31.         << fill_keyboard << " - Ввод с клавиатуры\r\n";
  32.  
  33.     int inp_method;
  34.     cin >> inp_method;
  35.     switch (inp_method) {
  36.     case fill_in_code:
  37.         break;
  38.     case fill_rand:
  39.         srand(static_cast<int>(time(0)));
  40.         for (int i = 0; i < N; i++)
  41.             for (int j = 0; j < N; j++)
  42.                 A[i][j] = rand() % 101;
  43.         break;
  44.     case fill_keyboard:
  45.         for (int i = 0; i < N; i++)
  46.             for (int j = 0; j < N; j++)
  47.                 cin >> A[i][j];
  48.         break;
  49.     default:
  50.         return 0;
  51.     }
  52.  
  53.     int min_value;
  54.  
  55.     for (int i = 0; i < N; i++) {
  56.         for (int j = 0; j < N; j++) {
  57.             int min_value = A[N - 1][N - 1];
  58.             for (int y = N - 1; y >= 0; y--) {
  59.                 for (int x = N - 1; x >= 0; x--)
  60.                     if (x + y >= i + j && A[y][x] < min_value) {
  61.                         min_value = A[y][x];
  62.                     }
  63.             }
  64.             B[j][i] = min_value;
  65.         }
  66.     }
  67.  
  68.     cout << setw(2 * N) << "Исходная матрица" << endl;
  69.     for (int y = 0; y < N; y++) {
  70.         for (int x = 0; x < N; x++) {
  71.             cout << setw(4) << A[y][x];
  72.         }
  73.         cout << endl;
  74.     }
  75.  
  76.     cout << setw(2 * N) << "Полученная матрица" << endl;
  77.     for (int y = 0; y < N; y++) {
  78.         for (int x = 0; x < N; x++) {
  79.             cout << setw(4) << B[y][x];
  80.         }
  81.         cout << endl;
  82.     }
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement