麻烦各位大佬看看
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
using namespace std;
int n,x = 1,y = 0,m = 1;
int a[10][10];
int main()
{
cin>>n;
while (m <= n * n)
{
while (y < n && !a[x][y + 1])
{
a[x][++y] = m++;
}
while (x < n && !a[x + 1][y])
{
a[++x][y] = m++;
}
while (y > 1 && !a[x][y - 1])
{
a[x][--y] = m++;
}
while (x > 1 && !a[x - 1][y])
{
a[--x][y] = m++;
}
}
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= n;j++)
{
cout<<" ";
if (a[i][j] < 10)
{
cout<<" ";
}
cout<<a[i][j]<<" ";
}
cout<<endl;
}
return 0;
}