Sum Frame of a Matrix T54397


Statement
 

pdf   zip   main.cc

Let MM be a square matrix N×NN \times N. This matrix has different frames. Frame 00 is formed by rows 00 and N1N-1 and columns 00 and N1N-1. Frame 11 is formed by rows 11 and N2N-2 and columns 11 and N2N-2, excluding the parts that are part of frame 00, etc.

In the following example, you have that the frame 00 is formed by all the positions where there is a 00, the frame 11 the positions where there is a 11, and the frame 22 the positions where there is a 22:

                          0  0  0  0  0
                          0  1  1  1  0
                          0  1  2  1  0
                          0  1  1  1  0
                          0  0  0  0  0

You must implement the function int sumaMarc(const Matriu& m, int x); with the following specification:

PRE: mm a matrix N×NN \times N and 0x<N/2+(Nmod2)0 \leq x < N/2 + (N~mod~2).

POST: Returns the sum of the elements of the frame xx of MM.

Observation

You only need to send the function we ask for and the functions you define. The rest will be ignored.

Input

A matrix N×NN \times N and 0x<N/2+(Nmod2)0 \leq x < N/2 + (N~mod~2).

Output

The sum of the elements of the frame xx of MM.

Sample session
ENTRADA 1:
5
1  1  1  1  1
1  2  2  2  1
1  2  3  2  1
1  2  2  2  1
1  1  1  1  1

0
1
2

SORTIDA 1:
El marc 0 suma 16
El marc 1 suma 16
El marc 2 suma 3


ENTRADA 2:
4
1  2  3  1
2  1  3  2
2  3  5  3
1  2  2  1

0
1

SORTIDA 2:
El marc 0 suma 22
El marc 1 suma 12


ENTRADA 3:
6
1  1  1  1  0  7
1  0  2  2  2  1
4  2  3  5  2  2
1  2  0  3  0  1
1  1  2  2  2  1
1  1  1  1  1  0

0
1
2

SORTIDA 3:
El marc 0 suma 28
El marc 1 suma 19
El marc 2 suma 11
Information
Author
PRO1
Language
English
Translator
Original language
Catalan
Other languages
Catalan Spanish
Official solutions
C++
User solutions
C++