#include<stdio.h> #include<string.h> #define MAXN 10 int a[MAXN][MAXN]; int main() { int n,t=0; while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); t=a[0][n-1]=1; int i=0,j=n-1; while(t<n*n) { while(i+1<n&&!a[i+1][j]) a[++i][j]=++t; while(j-1>=0&&!a[i][j-1]) a[i][--j]=++t; while(i-1>=0&&!a[i-1][j]) a[--i][j]=++t; while(j+1<n&&!a[i][j+1]) a[i][++j]=++t; } for(i=0;i<n;i++) { for(j=0;j<n;j++) printf("%d ",a[i][j]); printf("\n"); } } return 0; }
标签:int,++,while,MAXN,&&,--,方阵,回文 From: https://www.cnblogs.com/lhf123/p/17319979.html