提交时间:2019-12-14 14:20:34

运行 ID: 3189

#include<stdio.h> int a[1000][1000]; int main() { int n,i,j; scanf("%d",&n); a[0][n/2]=1; for(i=0;i>n;i++){ for(j=0;j<n;j++){ a[i][j]=0; } } int h,l; h=0; l=n/2; for(i=2;i<=n*n;i++){ if((h-1+n)%n>=0&&(l+1+n)%n>=0&&a[(h-1+n)%n][(l+1+n)%n]==0){ a[(h-1+n)%n][(l+1+n)%n]=i; h=(h-1+n)%n; l=(l+1+n)%n; } else if((h+1+n)%n>=0&&a[(h+1+n)%n][l]==0){ h=(h+1+n)%n; a[h][l]=i; } else if((h+1+n)%n>=0&&(l+1+n)%n>=0&&a[(h+1+n)%n][(l+1+n)%n]==0) { h=(h-1+n)%n; l=(l-1+n)%n; a[h][l]=i; } } for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("%d ",a[i][j]); } printf("\n"); } return 0; }