Adding up the neighbor values

In a matrix of integers, each position may have up to four immediate
neighbors: up and down by one row within the same column, and left and
right by one column within the same row. Corners have only two such
neighbors and the rest of the top and bottom rows have three, as do the
rest of the leftmost and rightmost column.

Write a program that reads several matrices and reports whether each
matrix has some position where the number in that position coincides
with the sum of the neighbors.

Input

Input consists of cases. First comes a non-negative integer k indicating
the number of cases. Then come the k cases, each of which starts with
two positive integers n and m, the dimensions of the matrix for that
case: n rows of m columns. Then come the contents of the matrix, row by
row.

Output

For each of the cases, your program must print the leftmost position in
the matrix containing a value equal to the sum of its neighbors; that
is, the one with smallest column index. In case of a tie, report the
topmost one; that is, the one with smallest row index. Row and column
indexes are to start from zero. The program must print the row and
column of the found position, as well as the value in it. Follow the
format of the examples.

If no position in the matrix fulfills the condition, the output for that
case must be the word "none".

Problem information

Author: José Luis Balcázar

Generation: 2026-01-25T15:54:16.902Z

© Jutge.org, 2006–2026.
https://jutge.org
