
Максимальный в области 2 Напишите программу, которая выводит максимальный элемент в
заштрихованной области квадратной матрицы.Формат входных данныхНа вход программе подаётся натуральное число nn — количество строк и столбцов в матрице, затем элементы матрицы.Формат выходных данныхПрограмма должна вывести одно число — максимальный элемент в заштрихованной области квадратной матрицы.Примечание. Элементы побочной диагонали также учитываются.Тестовые данные Sample Input 1:31 4 56 7 81 1 6Sample Output 1:8Sample Input 2:40 1 4 60 0 2 50 0 0 70 0 0 0Sample Output 2:7Sample Input 3:26 07 9Sample Output 3:9

Ответы на вопрос

Ответ:
cs = int(input()) # количество строк и столбцов в матрице
mat = [[input(f'{i+1} столбец, {j+1}: ') for j in range(cs)] for i in range(cs)] # заполняем элементы матрицы
maX = max([max(i) for i in mat]) # находим максимальное
print(maX) # выводим его.



Answer in detail. Maximum in area 2. Write a program that outputs the maximum element in the shaded area of a square matrix. Input format The program is given a natural number nn - the number of rows and columns in the matrix, then the elements of the matrix. Output format The program should output one number - the maximum element in the shaded area of a square matrix. Note. The elements of the secondary diagonal are also taken into account. Test data Sample Input 1: 3 1 4 5 6 7 8 1 1 6 Sample Output 1: 8 Sample Input 2: 4 0 1 4 6 0 0 2 5 0 0 0 7 0 0 0 0 Sample Output 2: 7 Sample Input 3: 2 6 0 7 9 Sample Output 3: 9
Here is a possible program in Python that solves this problem:
```python # Read the size of the matrix n = int(input())
# Initialize an empty matrix matrix = []
# Read the elements of the matrix row by row for i in range(n): row = list(map(int, input().split())) matrix.append(row)
# Initialize the maximum element to be the first element of the matrix max_element = matrix[0][0]
# Loop through the matrix and check the elements in the shaded area for i in range(n): for j in range(n): # The shaded area is the lower left triangle and the secondary diagonal if i >= j or i + j == n - 1: # Update the maximum element if needed if matrix[i][j] > max_element: max_element = matrix[i][j]
# Print the maximum element print(max_element) ```


Похожие вопросы







Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili