啊吧啊吧
2023-11-25 18:59:21
发布于:广东
7阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int n,m,a[1145][1145],cnt;
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
a[i][j]=++cnt;
int x=1,y=1;
cout<<a[x][y];
a[x][y]=0;
for(int i=2;i<=n*m;i++)
{
while(x+1<=n and a[x+1][y]!=0)
{
cout<<","<<a[++x][y];
a[x][y]=0;
}
while(y+1<=m and a[x][y+1]!=0)
{
cout<<","<<a[x][++y];
a[x][y]=0;
}
while(x-1>=0 and a[x-1][y]!=0)
{
cout<<","<<a[--x][y];
a[x][y]=0;
}
while(y+1>=0 and a[x][y-1]!=0)
{
cout<<","<<a[x][--y];
a[x][y]=0;
}
}
}
这里空空如也
有帮助,赞一个