JS
$\color{#9933ff}{Web应用-题解}$
思路:
观察可以发现,矩阵中每个数的大小其实是:$距离上下左右四个边界的最小值$
let buf = '';
process.stdin.on('readable', function() { // 输入
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
process.stdin.on('end', function() {
let ns = buf.split('\n').map(x => {return parseInt(x)});
for (let n of ns) {
if (n == 0) break;
for (let i = 0; i < n; i ++) {
let line = '';
for (let j = 0; j < n; j ++)
line += `${Math.min(i + 1, n - i, j + 1, n - j)} `;
console.log(line);
}
console.log();
}
});