【例62.2】 相邻数之和
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Description
Please write a program to calculate the sum of adjacent numbers for a given point in a 2D array. Adjacent numbers refer to the elements surrounding the point. If the point is at a corner or edge, the number of adjacent elements will be reduced accordingly.
For example, in the 2D array shown below: The value of element is , and its adjacent elements are with a sum of . Another example: The value of element is , and its adjacent elements are with a sum of .
1 2 3 4 5 6 7 8 9 10 3 4 5 7 8 2 5 6 8 0
Input Format
First line contains integers: , , , representing the height and width of the 2D array, and the row and column indices of the specified point respectively.
Next lines contain the int type 2D array . Where ; and ; note that indices start from .
Output Format
The sum of adjacent elements of .
Sample
4 5 2 3
1 2 3 4 5
6 7 8 9 10
3 4 5 7 8
2 5 6 8 054
20251108C班作业(6)
- Status
- Done
- Problem
- 4
- Open Since
- 2025-11-8 0:00
- Deadline
- 2025-11-16 23:59
- Extension
- 24 hour(s)