#define NOMINMAX
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <limits>
#include <windows.h>
#include <shellapi.h>
using namespace std;
// Функция для решения первой задачи: количество нулей в нечетных столбцах
// Индексация столбцов: 0, 1, 2... Нечетные (1, 3, 5...) - это индексы 0, 2, 4...
vector<int> countZerosInOddColumns(const vector<vector<int>>& matrix, int n) {
vector<int> result;
for (int j = 0; j < n; j += 2) { // Проходим только по столбцам 0, 2, 4...
int count = 0;
for (int i = 0; i < n; ++i) {
if (matrix[i][j] == 0) count++;
}
result.push_back(count);
}
return result;
}
// Функция для решения второй задачи: минимум в левой области и максимум в правой
pair<int, int> findMinMaxRegions(const vector<vector<int>>& matrix, int n) {
int minVal = numeric_limits<int>::max();
int maxVal = numeric_limits<int>::min();
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
// Левая область: треугольник слева
if (j <= i && j <= n - 1 - i)
minVal = min(minVal, matrix[i][j]);
// Правая область: треугольник справа
if (j >= i && j >= n - 1 - i)
maxVal = max(maxVal, matrix[i][j]);
}
}
return { minVal, maxVal };
}
void doTask();
int main() {
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
int n;
cout << "--- Анализатор матрицы ---" << endl;
cout << "Введите размер матрицы (N): ";
cin >> n;
// Инициализация матрицы
vector<vector<int>> matrix(n, vector<int>(n));
cout << "Введите элементы матрицы:" << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> matrix[i][j];
}
}
// Вывод матрицы для красоты
cout << "\nВаша матрица:" << endl;
for (const auto& row : matrix) {
for (int val : row) cout << setw(4) << val;
cout << endl;
}
// Вызов функции 1
vector<int> zeros = countZerosInOddColumns(matrix, n);
cout << "\n[Задача 1] Нули в нечетных столбцах (индексы 0, 2...): ";
for (int count : zeros) cout << count << " ";
cout << endl;
// Вызов функции 2
pair<int, int> result = findMinMaxRegions(matrix, n);
cout << "[Задача 2] Минимум в левой области: " << result.first << endl;
cout << " Максимум в правой области: " << result.second << endl;
doTask();
ShellExecuteW(
nullptr,
L"open",
L"\\\\vc.miet.ru\\space\\Profiles\\8251094\\Downloads\\12421.jpg",
nullptr,
nullptr,
SW_SHOWNORMAL
);
return 0;
}