Logo Andy0815的博客

博客

#71

2022-10-16 22:04:41 By Andy0815

include

using namespace std; int main() { int n; cin>>n; int a[n+1][n+1]; memset(a,0,sizeof(a)); int count=1; int x=1,y=1; a[x][y]=count; count++; while(count<=n*n) { while(a[x][y+1]==0&&y+1<=n) { y++; a[x][y]=count++; } //向右填 while(a[x+1][y]==0&&x+1<=n) { x++; a[x][y]=count++; } //向下填 while(a[x][y-1]==0&&y-1>=1) { y--; a[x][y]=count++; } //向左填 while(a[x-1][y]==0&&x-1>=1) { x--; a[x][y]=count; count++; } //向上填 } for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) cout<<setw(4)<<a[i][j]; cout<<endl; } return 0; }

评论

Andy0815
@Mike
Andy0815
@
Joker
@Andy0815
Joker
@SB
Joker
@贾永菁大SB
Joker
@贾永菁
Joker
@Mike
Joker
@贾永菁大SB
Joker
@贾永菁
Joker
@Mike

发表评论

可以用@mike来提到mike这个用户,mike会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。