#K61067. Matrix Diagonal Transformation
Matrix Diagonal Transformation
Matrix Diagonal Transformation
Given a square matrix A of size n × n, perform the following transformation:
- Compute the sum of the primary diagonal: \(S_1 = \sum_{i=0}^{n-1} A[i][i]\).
- Compute the sum of the secondary diagonal: \(S_2 = \sum_{i=0}^{n-1} A[i][n-1-i]\).
- Replace each element on the primary diagonal with \(S_1\).
- Replace each element on the secondary diagonal with \(S_2\).
You are required to read the matrix from standard input, perform the transformation, and then print the transformed matrix to standard output.
Note: The input and output are handled via stdin and stdout respectively.
inputFormat
The first line contains a single integer n denoting the size of the matrix. The following n lines each contain n space-separated integers representing the rows of the matrix.
outputFormat
Output the transformed matrix with n lines. Each line should contain n space-separated integers corresponding to the modified row of the matrix.## sample
3
1 2 3
4 5 6
7 8 9
15 2 15
4 15 6
15 8 15
</p>