解题思路:
注意事项:
参考代码:
#include
using namespace std;
int main()
{
int j;
int a[100][100] = { 0 };
while (cin >> j)
{
if (j != 1)
{
for (int u = 1; u < j; u++)
{
for (int z = u; z <= j + 1 - u; z++)
{
a[z][j - u + 1] = a[z - 1][j - u + 1] + 1;
}
for (int y = j - u; y >= u; y--)
{
a[j - u + 1][y] = a[j - u + 1][y + 1] + 1;
}
for (int m = j - u; m >= u; m--)
{
a[m][u] = a[m + 1][u] + 1;
}
for (int g = u + 1; g < j - u + 1; g++)
{
a[u][g] = a[u][g - 1] + 1;
}
}
for (int i = 1; i <= j; i++)
{
for (int q = 1; q <= j; q++) //打印数组
{
cout << a[i][q];
if (q != j)cout << " ";
}
cout << endl;
}
}
else
cout << "1" << endl;
cout << endl;
}
return 0;
}