//用循环硬算3×3魔方阵
#include<stdio.h>
int B[]={0,1,1,1,1,1,1,1,1,1};//1:空闲,0:已用
#define a m[0][0]
#define b m[0][1]
#define c m[0][2]
#define d m[1][0]
#define e m[1][1]
#define f m[1][2]
#define g m[2][0]
#define h m[2][1]
#define i m[2][2]
main()
{
int m[3][3],j,k;
int OK(int[][3]);
for(a=1;a<=9;a++){B[a]=0;
for(b=1;b<=9;b++)if(B[b]){B[b]=0;
for(c=1;c<=9;c++)if(B[c]){B[c]=0;
if(a+b+c==15)/*提速指令1*/
for(d=1;d<=9;d++)if(B[d]){B[d]=0;
for(e=1;e<=9;e++)if(B[e]){B[e]=0;
for(f=1;f<=9;f++)if(B[f]){B[f]=0;
if(d+e+f==15)/*提速指令2*/
for(g=1;g<=9;g++)if(B[g]){B[g]=0;
for(h=1;h<=9;h++)if(B[h]){B[h]=0;
for(i=1;i<=9;i++)if(B[i])
if(g+h+i==15)/*提速指令3*/
if(OK(m)){printf("\nsolution:\n");
for(j=0;j<3;j++,printf("\n"))
for(k=0;k<3;k++)printf("%3d",m[j][k]);}
B[h]=1;}
B[g]=1;}
B[f]=1;}
B[e]=1;}
B[d]=1;}
B[c]=1;}
B[b]=1;}
B[a]=1;}
}
int OK(int n[][3])
{
int j,k,s;
for(j=0;j<3;j++){
for(s=k=0;k<3;k++)
s+=n[k][j];
if(s-15)return 0;}
if(n[0][0]+n[1][1]+n[2][2]-15)return 0;
return !(n[2][0]+n[1][1]+n[0][2]-15);
}