#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n;
int a[50][50];
int main()
{
cin>>n;
int t=0;
int quan=n/2+(n%2);
for(int st=1;st<=quan;st++)
{
for(int i=st;i<=n;i++) a[st][i]=++t;
for(int i=st+1;i<=n-st+1;i++) a[i][n-st+1]=++t;
for(int i=n-st;i>=st;i--) a[n-st+1][i]=++t;
for(int i=n-st-1;i>=st+1;i--) a[i][st]=++t;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++) cout<<a[i][j]<<" ";
cout<<endl;
}
return 0;
}
自己看了好几遍,可不止问题出在哪。
输入:
4
输出:
1 2 3 4
11 12 13 14
0 16 15 6
10 9 8 7