1 #include<bits/stdc++.h> 2 using namespace std; 3 int main(){ 4 int n; 5 cin>>n; 6 int a[n][n],i=0,j=n-1,t=1; 7 memset(a,0,sizeof(a)); 8 a[i][j]=1; 9 while(t!=n*n){ 10 while(a[i+1][j]==0&&i+1<n){ 11 a[++i][j]=++t; 12 } 13 while(a[i][j-1]==0&&j-1>=0){ 14 a[i][--j]=++t; 15 } 16 while(a[i-1][j]==0&&i-1>=0){ 17 a[--i][j]=++t; 18 } 19 while(a[i][j+1]==0&&j+1<n){ 20 a[i][++j]=++t; 21 } 22 } 23 for(int i=0;i<n;i++){ 24 for(int j=0;j<n;j++){ 25 cout<<a[i][j]<<" "; 26 } 27 cout<<endl; 28 } 29 }
标签:2045,int,++,5.13,while,填数,&& From: https://www.cnblogs.com/liujiaxing-/p/18024892