F003A. Pentadiagonal matrices P55168


Statement
 

pdf   zip

html

A square matrix is called pentadiagonal if all the elements out of the main diagonal and of the two diagonals over and under the main diagonal are 0.

For instance, the matrix on the left is pentadiagonal, but, the matrix on the right is not (it would be pentadiagonal if the 9 on the second and the sixth row were 0).

2 ‍ ‍0 ‍ ‍1 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0     5 ‍ ‍6 ‍ ‍7 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0
9 ‍ ‍4 ‍ ‍1 ‍ ‍1 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0     1 ‍ ‍7 ‍ ‍3 ‍ ‍6 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍9 ‍ ‍0 ‍ ‍0
1 ‍ ‍1 ‍ ‍5 ‍ ‍1 ‍ ‍5 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0     1 ‍ ‍7 ‍ ‍0 ‍ ‍7 ‍ ‍3 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0
0 ‍ ‍6 ‍ ‍3 ‍ ‍2 ‍ ‍5 ‍ ‍1 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0     0 ‍ ‍8 ‍ ‍7 ‍ ‍8 ‍ ‍1 ‍ ‍4 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0
0 ‍ ‍0 ‍ ‍2 ‍ ‍1 ‍ ‍5 ‍ ‍1 ‍ ‍1 ‍ ‍0 ‍ ‍0 ‍ ‍0     0 ‍ ‍0 ‍ ‍8 ‍ ‍2 ‍ ‍1 ‍ ‍4 ‍ ‍1 ‍ ‍0 ‍ ‍0 ‍ ‍0
0 ‍ ‍0 ‍ ‍0 ‍ ‍1 ‍ ‍9 ‍ ‍0 ‍ ‍9 ‍ ‍9 ‍ ‍0 ‍ ‍0     0 ‍ ‍0 ‍ ‍9 ‍ ‍5 ‍ ‍1 ‍ ‍4 ‍ ‍1 ‍ ‍1 ‍ ‍0 ‍ ‍0
0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍5 ‍ ‍1 ‍ ‍1 ‍ ‍1 ‍ ‍8 ‍ ‍0     0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍1 ‍ ‍4 ‍ ‍4 ‍ ‍5 ‍ ‍6 ‍ ‍0
0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍5 ‍ ‍1 ‍ ‍5 ‍ ‍2 ‍ ‍4     0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍6 ‍ ‍8 ‍ ‍7 ‍ ‍7 ‍ ‍2
0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍4 ‍ ‍5 ‍ ‍4 ‍ ‍4     0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍8 ‍ ‍4 ‍ ‍0 ‍ ‍0
0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍5 ‍ ‍5 ‍ ‍7     0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍0 ‍ ‍7 ‍ ‍5 ‍ ‍5

Using the definition

Implement the function

that prints whether |mat| is pentadiagonal or it is not.

Also, using the definition

int sum; int max; };

Implement the procedure

that stores in the fields |sum| and |max| of the output parameter |inf| the sum and the maximum of all the |mat| elements, under the precondition that |mat| is pentadiagonal.

The main program is already done; do not modify it. It reads square matrices of integers, and for each one, if the matrix is pentadiagonal, writes the sum and the maximum of its elements; Otherwise, it prints that the matrix is not pentadiagonal.

Precondition

The matrices |mat| are n× n with n≥6.

Public test cases
  • Input

    10
    2 0 1 0 0 0 0 0 0 0
    9 4 1 1 0 0 0 0 0 0
    1 1 5 1 5 0 0 0 0 0
    0 6 3 2 5 1 0 0 0 0
    0 0 2 1 5 1 1 0 0 0
    0 0 0 1 9 0 9 9 0 0
    0 0 0 0 5 1 1 1 8 0
    0 0 0 0 0 5 1 5 2 4
    0 0 0 0 0 0 4 5 4 4
    0 0 0 0 0 0 0 5 5 7
    
    10
    5 6 7 0 0 0 0 0 0 0
    1 7 3 6 0 0 0 9 0 0
    1 7 0 7 3 0 0 0 0 0
    0 8 7 8 1 4 0 0 0 0
    0 0 8 2 1 4 1 0 0 0
    0 0 9 5 1 4 1 1 0 0
    0 0 0 0 1 4 4 5 6 0
    0 0 0 0 0 6 8 7 7 2
    0 0 0 0 0 0 8 4 0 0
    0 0 0 0 0 0 0 7 5 5
    
    6
    -1  0  1  0  0  0
     0 -1  0  1  0  0
     1  0 -1  0  1  0
     0  1  0 -1  0  1
     0  0  1  0 -1  0
     0  0  0  1  0 -1
    
    6
    -17 -17 -17   0   0   0
    -17 -17 -17 -17   0   0
    -17 -17 -17 -17 -17   0
      0 -17 -17 -17 -17 -17
      0   0 -17 -17 -17 -17
      0   0   0 -17 -17 -17
    

    Output

    153 9
    no es pentadiagonal
    2 1
    -408 0
    
  • Information
    Author
    Professorat de P1
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++