Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <time.h>
- #include <iomanip>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "rus");
- const int N_MAX = 100;
- cout << "Порядок матрицы <= " << N_MAX << ". N = ";
- int N;
- cin >> N;
- if (N > N_MAX)
- N = N_MAX;
- else if (N < 0)
- N = 0;
- int A[N_MAX][N_MAX] = {};
- int B[N_MAX][N_MAX] = {};
- enum
- {
- fill_in_code,
- fill_rand,
- fill_keyboard,
- };
- cout << "Выберите способ ввода элементов массива\r\n"
- << fill_in_code << " - Инициализация в коде\r\n"
- << fill_rand << " - Заполнение случайными числами\r\n"
- << fill_keyboard << " - Ввод с клавиатуры\r\n";
- int inp_method;
- cin >> inp_method;
- switch (inp_method) {
- case fill_in_code:
- break;
- case fill_rand:
- srand(static_cast<int>(time(0)));
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- A[i][j] = rand() % 101;
- break;
- case fill_keyboard:
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- cin >> A[i][j];
- break;
- default:
- return 0;
- }
- int min_value;
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < N; j++) {
- int min_value = A[N - 1][N - 1];
- for (int y = N - 1; y >= 0; y--) {
- for (int x = N - 1; x >= 0; x--)
- if (x + y >= i + j && A[y][x] < min_value) {
- min_value = A[y][x];
- }
- }
- B[j][i] = min_value;
- }
- }
- cout << setw(2 * N) << "Исходная матрица" << endl;
- for (int y = 0; y < N; y++) {
- for (int x = 0; x < N; x++) {
- cout << setw(4) << A[y][x];
- }
- cout << endl;
- }
- cout << setw(2 * N) << "Полученная матрица" << endl;
- for (int y = 0; y < N; y++) {
- for (int x = 0; x < N; x++) {
- cout << setw(4) << B[y][x];
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement