You are given a matrix with size N * N. You need to print the summation for each of the rows, followed by each of the columns, followed by the two diagonals (among the diagonals, print major diagonal first, and then minor diagonal), and finally the sum of all values in the matrix.
The problem looks very straightforward, doesn’t it? But as you all know that Dr. Bari doesn’t like straightforward problems, he makes the problem a bit difficult.
Instead of taking numbers as input, you will be taking English letters (a-z, A-Z) as input to each cell of the matrix. For computation, you will consider the first letter of the English alphabet ‘a’ or ‘A’ having the value 1. Subsequent letters will have value 2, 3, …, 26. (e.g.: ‘b’ or ‘B’ as 2, ‘c’ or ‘C’ as 3, …, ‘z’ or ‘Z’ as 26).
First line of input will contain the value N (0 < N <100). Following N lines will contain N characters on each line denoting each row of the matrix.
First print the summation for each of the N rows, followed by each of the N columns, followed by the two diagonals (major diagonal sum should be followed by minor diagonal), and finally the sum of all values in the matrix. Each result should be separated by a newline.
2 b a r i
3 27 20 10 11 19 30
Input Explanation2 118 9
Output Explanation2+1 -> 318 + 9 -> 272 + 18 -> 201 + 9 -> 102 + 9 -> 111 + 18 -> 192+ 1 + 18 + 9 -> 30
Login to submit