点击打开链接
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<math.h>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;
int Arr[110][110];
int main()
{
int n=0,num=0,i=0,j=0;
while(cin>>n)
{
num=0,i=0,j=0;
memset(Arr,0,sizeof(Arr));
Arr[1][n]=1;
i=1,j=n;
num++;
while(num<n*n)
{
while(i+1<=n&&Arr[i+1][j]==0)//
{ i+=1;
num+=1;
Arr[i][j]=num;
}
while(j-1>=1&&Arr[i][j-1]==0)
{
j-=1;
num+=1;
Arr[i][j]=num;
}
while(i-1>=1&&Arr[i-1][j]==0)
{
i-=1;
num+=1;
Arr[i][j]=num;
}
while(j+1<=n&&Arr[i][j+1]==0)
{
j+=1;
num+=1;
Arr[i][j]=num;
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cout<<Arr[i][j]<<" ";
}
cout<<endl;
}
}
return 0;
}