-->
当前位置:首页 > 题库

PROGRAMMING:Conditional summation of matrix elements

Luz5年前 (2021-05-10)题库465
Given a two-dimensional array with M rows and N columns, please find out the only element with a value of 0 in the two-dimensional array, change all the elements in the eight directions directly adjacent to it to 0, and then find the sum of all the numbers in the matrix.
The eight directly adjacent directions include: up, down, left, right, left up, left down, right up and right down. Ignored if the array boundary is exceeded.
Data must have and only have one 0 element.
###Input format:
First, enter m and N to represent the number of rows and columns of the two-dimensional matrix, 5 < = m, n < = 100
Then enter each line, n integers per line, separated by spaces.
###Output format:
Output the sum of all elements of the modified two-dimensional array. After outputting the data, you need to output carriage return and line feed.
###Input example:
Here is a set of inputs. For example:
```in
5 5
1 2 3 4 5
1 2 3 4 5
1 2 0 4 5
1 2 3 4 5
1 2 3 4 5
```
###Output example:
The corresponding output is given here. For example:
```out
forty-eight
```






answer:If there is no answer, please comment