这是道SB模拟题,NOIP--难度
直接贴代码
#include<iostream> #include<cstdio> using namespace std; int n,num=1,zong,heng; int f[41][41]; int main(){ scanf("%d",&n); heng=n/2+1; zong=1; while(num<=n*n){ f[heng][zong]=num; if(f[heng+1][zong-1]||((heng+1>n)&&(zong-1==0)))zong++; else if(heng+1>n)heng=1,zong--; else if(zong-1==0)zong=n,heng++; else heng++,zong--; num++; } for(int i=1;i<=n;i++) { for(int j=1;j<n;j++) printf("%d ",f[j][i]); printf("%d\n",f[n][i]); } return 0; }
时间: 2024-10-25 03:08:48