求救,输出有个0
查看原帖
求救,输出有个0
525942
Groot_Von_Hafmman楼主2021/12/11 15:02
#include <bits/stdc++.h>
using namespace std;
const int MAXN=10+5;
int a[MAXN][MAXN];
int main()
{
	int n;
	int cnt=0,heng=1,shu=0;
	cin>>n;
	while (cnt<n*n)
	{
		while (shu<n &&!a[heng][shu+1]) a[heng][shu++]=cnt++;
		while (heng<n &&!a[heng+1][shu]) a[heng++][shu]=cnt++;
		while (shu>1 &&!a[heng][shu-1]) a[heng][shu--]=cnt++;
		while (heng>1 &&!a[heng-1][shu]) a[heng--][shu]=cnt++;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			if (a[i][j]<10) cout<<' ';
			cout<<a[i][j]<<' ';	 
		}	
 		cout<<endl;
	}	
	
	
	
	return 0;
}
2021/12/11 15:02
加载中...