标签:div std -- i++ name amp class pre span
1 #include <cstdio> 2 using namespace std; 3 int n,a[50][50]; 4 int main(){ 5 scanf("%d",&n); 6 int x,y; 7 x=1; 8 y=n/2+1; 9 a[x][y]=1; 10 for(int i=2;i<=n*n;i++){ 11 if(x==1&&y!=n){ 12 x=n; 13 y++; 14 a[x][y]=i; 15 continue; 16 } 17 if(x!=1&&y==n){ 18 x--; 19 y=1; 20 a[x][y]=i; 21 continue; 22 } 23 if(x==1&&y==n){ 24 x++; 25 a[x][y]=i; 26 continue; 27 } 28 if(x!=1&&y!=n){ 29 if(a[x-1][y+1]==0){ 30 x--; 31 y++; 32 } 33 else{ 34 x++; 35 } 36 a[x][y]=i; 37 continue; 38 } 39 } 40 for(int i=1;i<=n;i++){ 41 for(int j=1;j<=n;j++){ 42 printf("%d ",a[i][j]); 43 } 44 printf("\n"); 45 } 46 return 0; 47 }
标签:div std -- i++ name amp class pre span
原文地址:https://www.cnblogs.com/iat14/p/11225140.html