1 #include<stdio.h> 2 #include<string.h> 3 int a[105][105]; 4 int main() 5 { 6 int n,i,j,t; 7 while(~scanf("%d",&n)) 8 { 9 memset(a,0,sizeof a); 10 t=a[i=0][j=n-1]=1; 11 while(t<n*n) 12 { 13 while(i+1<n && !a[i+1][j]) a[++i][j]=++t; 14 while(j-1>=0 && !a[i][j-1]) a[i][--j]=++t; 15 while(i-1>=0 && !a[i-1][j]) a[--i][j]=++t; 16 while(j+1<n && !a[i][j+1]) a[i][++j]=++t; 17 } 18 for(i=0; i<n; ++i) 19 { 20 for(j=0; j<n; ++j) 21 if(j) 22 printf(" %d",a[i][j]); 23 else 24 printf("%d",a[i][j]); 25 printf(" "); 26 } 27 } 28 }