2017-03-14 02:15
采纳率: 92.7%
浏览 832

Nearest number

Input is the matrix A of N by N non-negative integers.

A distance between two elements Aij and Apq is defined as |i - p| + |j - q|.

Your program must replace each zero element in the matrix with the nearest non-zero one. If there are two or more nearest non-zeroes, the zero must be left in place.


1 <= N <= 200, 0 <= Ai <= 1000000


Input contains the number N followed by N^2 integers, representing the matrix row-by-row.


Output must contain N^2 integers, representing the modified matrix row-by-row.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Sample Input


0 0 0
1 0 2
0 3 0

Sample Output

1 0 2
1 0 2
0 3 0

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新