求助
查看原帖
求助
1089320
WFong楼主2024/3/10 10:13

求助为什么一直无法正常输出啊

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,x=1,y=0;
	cin>>a;
	int s[20][20];
	int m=1;
	while(m<=a*a)
	{
		while(y<a&&!s[x][y+1])
			s[x][++y]=m++;
		while(x<a&&!s[x+1][y])
			s[++x][y]=m++;
		while(y>1&&!s[x][y-1])
			s[x][--y]=m++;
		while(x>1&&!s[x-1][y])
			s[--x][y]=m++;
	}
	for(int i=1;i<=a;i++)
	{
		for (int j=1;j<=a;j++)
			cout<<setw(3)<<s[i][j];
		cout<<endl;
	}	
	return 0;
}
2024/3/10 10:13
加载中...