一大淼题,直接瞎搞即可,不过一定要仔细看题目给定的条件。
#include<iostream>
#include<cstdio>
#include<cstring>
#define M 50
using namespace std;
int a[M][M]={};
int main(){
freopen("magic.in","r",stdin);
freopen("magic.out","w",stdout);
int n; cin>>n;
int lastx=,lasty=+(n>>); a[lastx][lasty]=;
for(int i=;i<=n*n;i++){
if(lastx==&&lasty!=n){a[lastx=n][++lasty]=i; continue;}
if(lastx!=&&lasty==n){a[--lastx][lasty=]=i; continue;}
if(lastx==&&lasty==n){a[++lastx][lasty]=i; continue;}
if(lastx!=&&lasty!=n){
if(a[lastx-][lasty+]==)
a[--lastx][++lasty]=i;
else a[++lastx][lasty]=i;
continue;
}
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++) printf("%d ",a[i][j]);
printf("\n");
}
}