提交时间:2024-03-23 17:27:21

运行 ID: 139473

#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1][n + 1]; int x = (n + 1) / 2; for(int k = 1;k <= x;k++) { for(int i = x + 1 - k;i <= n - x + k;i++) { int t = x - k + 1; a[n - x + k][i] = t; a[i][n - x + k] = t; a[x + 1 - k][i] = t; a[i][x + 1 - k] = t; } } for(int i = 1;i <= n;i++) { for(int j = 1;j <= n;j++) { cout << setw(5) << a[i][j]; } cout << endl; } }