#C8310. Find Maximum Element in a 2D Matrix
Find Maximum Element in a 2D Matrix
Find Maximum Element in a 2D Matrix
You are given a 2D matrix of integers. Your task is to find and print the maximum element in the matrix.
The input begins with an integer representing the number of rows. If this value is 0, the matrix is considered empty and your program should output IndexError
to indicate an error. Otherwise, each of the following lines contains one row of the matrix, with integers separated by spaces.
Note: The matrix may have variable number of columns per row, but each row will contain at least one integer if the matrix is not empty.
Example:
Input: 3 7 3 8 5 6 9 12 10 4 2 11 1</p>Output: 12
Solve the problem by reading from standard input and writing the result to standard output.
inputFormat
The first line contains an integer R representing the number of rows in the matrix. If R = 0, then the matrix is empty.
For each of the next R lines, there is a row of the matrix containing one or more space-separated integers.
outputFormat
Print the maximum element in the matrix. If the matrix is empty (R = 0), print IndexError
.
3
7 3 8 5
6 9 12 10
4 2 11 1
12