Вопрос задан 28.11.2023 в 15:14. Предмет Информатика. Спрашивает Жиляев Ростислав.

Максимальный в области 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​
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Первых Ваня.

Ответ:

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) # выводим его.

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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) ```

0 0

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

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

Последние заданные вопросы в категории Информатика

Задать вопрос