Problem 996
Largest Local Values in a Matrix
Easy · 10 pts · Matrix
Problem
For an N × N matrix, build an (N - 2) × (N - 2) matrix where the cell at (i, j) holds the largest value of the 3 × 3 block of the original matrix whose top-left corner is (i, j). In other words, take the maximum around every interior cell of the original. Print the new matrix. With N up to 100, checking all nine cells for every output cell is fast enough.
Input
The first line contains N. Each of the next N lines contains N integers.
Output
Print the (N - 2) × (N - 2) matrix, one row per line.
Constraints
3 <= N <= 100; 1 <= value <= 100
Example input
4 9 9 8 1 5 6 2 6 8 2 6 4 6 2 2 2
Example output
9 9 8 6
Explanation
For 9 9 8 1 / 5 6 2 6 / 8 2 6 4 / 6 2 2 2, the top-left 3 × 3 block has maximum 9, and the others give 9, 8 and 6. The result is 9 9 / 8 6.