求助
查看原帖
求助
348852
user107楼主2022/7/4 22:25

代码如下

#include <iostream>
using namespace std;
int shu[40][40];
int main()
{
	int n,x,y;
	cin>>n;
	shu[(n+1)/2][1]=1;
	x=(n+1)/2;y=1;
	for(int i=1;i<=n*n;i++)
	{
		if((y==1)&&(x!=n))
		{
			shu[x+1][n]=i+1;
			x++;y=n;
		}
		else
		{
			if((x= n)&&(y!=1))
		    {
			    shu[1][y-1]=i+1;
			    x=1;y--;
		    }
		    else
		    {
		    	if((x==n)&&(y==1))
		    	{
		    		shu[x][y+1]=i+1;
		    		y++;
				}
				else
				{
					if(shu[x+1][y-1]==0)
					{
						shu[x+1][y-1]=i+1;
						x++;y--;
					}
					else
					{
						shu[x][y+1]=i+1;
		    		    y++;
					}
				}
			}
		}
	}
	for(int a=1;a<=n;a++)
	{
		for(int b=1;b<=n;b++)
		{
			cout<<shu[a][b]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

我觉得默问题啊,为啥就10分。我的电脑还编译不了,我运行不了,求大神指点。

2022/7/4 22:25
加载中...