#K43707. Tablet Energy Value
Tablet Energy Value
Tablet Energy Value
You are given a square matrix of integers along with an operation. Your task is to compute the energy value of a tablet by combining the stone values (elements of the matrix) using the specified operation. First, flatten the matrix in row‐major order, then combine the values consecutively using the given operation. The available operations are:
(+): addition, (*): multiplication, (\max): maximum, and (\min): minimum.
For example, if the input matrix is (\begin{bmatrix} 4 & 2 & 9 \ 1 & 6 & 3 \ 5 & 0 & 7 \end{bmatrix}) and the operation is ( + ), then the computed energy value is 37.
inputFormat
The input is read from standard input (stdin) and consists of multiple lines. The first line contains an integer (n), the size of the matrix. This is followed by (n) lines, each containing (n) space-separated integers representing the rows of the matrix. The last line contains a string which is the operation. The operation is one of the following: "+", "*", "max", or "min".
outputFormat
Output to standard output (stdout) a single integer, which is the energy value computed by consecutively applying the given operation on the matrix elements.## sample
3
4 2 9
1 6 3
5 0 7
+
37