程序代码:
float cheng(int j[],float h[6][6])
{float g=1,i,z;
int *f;
int a,b,c=0,d,e;
for(a=1;a<=5;a++)
for(b=a;b<=4;b++)
if(j[a]>j[b+1]) c++;
if(c%2==0) d=1;
else d=-1;
for(e=1,f=j+1;e<=5;e++,f++)
{z=h[e][*f]; g=g*z;}
i=d*g;
return(i);}
float hang( float k[6][6])
{float r;
int p11[6]={0,5,1,2,3,4}; int p21[6]={0,5,1,2,4,3}; int p31[6]={0,5,1,3,2,4};
int p41[6]={0,5,1,3,4,2}; int p51[6]={0,5,1,4,2,3}; int p61[6]={0,5,1,4,3,2};
int p71[6]={0,5,2,1,3,4}; int p81[6]={0,5,2,1,4,3}; int p91[6]={0,5,2,3,1,4};
int p101[6]={0,5,2,3,4,1};int p111[6]={0,5,2,4,1,3};int p121[6]={0,5,2,4,3,1};
int p131[6]={0,5,3,1,2,4};int p141[6]={0,5,3,1,4,2};int p151[6]={0,5,3,2,1,4};
int p161[6]={0,5,3,2,4,1};int p171[6]={0,5,3,4,1,2};int p181[6]={0,5,3,4,2,1};
int p191[6]={0,5,4,1,2,3};int p201[6]={0,5,4,1,3,2};int p211[6]={0,5,4,2,3,1};
int p221[6]={0,5,4,2,1,3};int p231[6]={0,5,4,3,1,2};int p241[6]={0,5,4,3,2,1};
int p12[6]={0,1,5,2,3,4}; int p22[6]={0,1,5,2,4,3}; int p32[6]={0,1,5,3,2,4};
int p42[6]={0,1,5,3,4,2}; int p52[6]={0,1,5,4,2,3}; int p62[6]={0,1,5,4,3,2};
int p72[6]={0,2,5,1,3,4}; int p82[6]={0,2,5,1,4,3}; int p92[6]={0,2,5,3,1,4};
int p102[6]={0,2,5,3,4,1};int p112[6]={0,2,5,4,1,3};int p122[6]={0,2,5,4,3,1};
int p132[6]={0,3,5,1,2,4};int p142[6]={0,3,5,1,4,2};int p152[6]={0,3,5,2,1,4};
int p162[6]={0,3,5,2,4,1};int p172[6]={0,3,5,4,1,2};int p182[6]={0,3,5,4,2,1};
int p192[6]={0,4,5,1,2,3};int p202[6]={0,4,5,1,3,2};int p212[6]={0,4,5,2,3,1};
int p222[6]={0,4,5,2,1,3};int p232[6]={0,4,5,3,1,2};int p242[6]={0,4,5,3,2,1};
int p13[6]={0,1,2,5,3,4}; int p23[6]={0,1,2,5,4,3}; int p33[6]={0,1,3,5,2,4};
int p43[6]={0,1,3,5,4,2}; int p53[6]={0,1,4,5,2,3}; int p63[6]={0,1,4,5,3,2};
int p73[6]={0,2,1,5,3,4}; int p83[6]={0,2,1,5,4,3}; int p93[6]={0,2,3,5,1,4};
int p103[6]={0,2,3,5,4,1};int p113[6]={0,2,4,5,1,3};int p123[6]={0,2,4,5,3,1};
int p133[6]={0,3,1,5,2,4};int p143[6]={0,3,1,5,4,2};int p153[6]={0,3,2,5,1,4};
int p163[6]={0,3,2,5,4,1};int p173[6]={0,3,4,5,1,2};int p183[6]={0,3,4,5,2,1};
int p193[6]={0,4,1,5,2,3};int p203[6]={0,4,1,5,3,2};int p213[6]={0,4,2,5,3,1};
int p223[6]={0,4,2,5,1,3};int p233[6]={0,4,3,5,1,2};int p243[6]={0,4,3,5,2,1};
int p14[6]={0,1,2,3,5,4}; int p24[6]={0,1,2,4,5,3}; int p34[6]={0,1,3,2,5,4};
int p44[6]={0,1,3,4,5,2}; int p54[6]={0,1,4,2,5,3}; int p64[6]={0,1,4,3,5,2};
int p74[6]={0,2,1,3,5,4}; int p84[6]={0,2,1,4,5,3}; int p94[6]={0,2,3,1,5,4};
int p104[6]={0,2,3,4,5,1};int p114[6]={0,2,4,1,5,3};int p124[6]={0,2,4,3,5,1};
int p134[6]={0,3,1,2,5,4};int p144[6]={0,3,1,4,5,2};int p154[6]={0,3,2,1,5,4};
int p164[6]={0,3,2,4,5,1};int p174[6]={0,3,4,1,5,2};int p184[6]={0,3,4,2,5,1};
int p194[6]={0,4,1,2,5,3};int p204[6]={0,4,1,3,5,2};int p214[6]={0,4,2,3,5,1};
int p224[6]={0,4,2,1,5,3};int p234[6]={0,4,3,1,5,2};int p244[6]={0,4,3,2,5,1};
int p15[6]={0,1,2,3,4,5}; int p25[6]={0,1,2,4,3,5}; int p35[6]={0,1,3,2,4,5};
int p45[6]={0,1,3,4,2,5}; int p55[6]={0,1,4,2,3,5}; int p65[6]={0,1,4,3,2,5};
int p75[6]={0,2,1,3,4,5}; int p85[6]={0,2,1,4,3,5}; int p95[6]={0,2,3,1,4,5};
int p105[6]={0,2,3,4,1,5};int p115[6]={0,2,4,1,3,5};int p125[6]={0,2,4,3,1,5};
int p135[6]={0,3,1,2,4,5};int p145[6]={0,3,1,4,2,5};int p155[6]={0,3,2,1,4,5};
int p165[6]={0,3,2,4,1,5};int p175[6]={0,3,4,1,2,5};int p185[6]={0,3,4,2,1,5};
int p195[6]={0,4,1,2,3,5};int p205[6]={0,4,1,3,2,5};int p215[6]={0,4,2,3,1,5};
int p225[6]={0,4,2,1,3,5};int p235[6]={0,4,3,1,2,5};int p245[6]={0,4,3,2,1,5};
r=cheng(p11,k); r=r+cheng(p21,k); r=r+cheng(p31,k); r=r+cheng(p41,k);
r=r+cheng(p51,k); r=r+cheng(p61 ,k); r=r+cheng(p71 ,k); r=r+cheng(p81 ,k);
r=r+cheng(p91 ,k); r=r+cheng(p101 ,k);r=r+cheng(p111 ,k);r=r+cheng(p121 ,k);
r=r+cheng(p131 ,k);r=r+cheng(p141 ,k);r=r+cheng(p151 ,k);r=r+cheng(p161 ,k);
r=r+cheng(p171 ,k);r=r+cheng(p181 ,k);r=r+cheng(p191 ,k);r=r+cheng(p201 ,k);
r=r+cheng(p211 ,k);r=r+cheng(p221 ,k);r=r+cheng(p231 ,k);r=r+cheng(p241 ,k);
r=r+cheng(p12,k); r=r+cheng(p22,k); r=r+cheng(p32,k); r=r+cheng(p42,k);
r=r+cheng(p52,k); r=r+cheng(p62 ,k); r=r+cheng(p72 ,k); r=r+cheng(p82 ,k);
r=r+cheng(p92,k); r=r+cheng(p102 ,k);r=r+cheng(p112 ,k);r=r+cheng(p122 ,k);
r=r+cheng(p132 ,k);r=r+cheng(p142 ,k);r=r+cheng(p152 ,k);r=r+cheng(p162 ,k);
r=r+cheng(p172 ,k);r=r+cheng(p182 ,k);r=r+cheng(p192 ,k);r=r+cheng(p202 ,k);
r=r+cheng(p212 ,k);r=r+cheng(p222 ,k);r=r+cheng(p232 ,k);r=r+cheng(p242 ,k);
r=r+cheng(p13,k); r=r+cheng(p23,k); r=r+cheng(p33,k); r=r+cheng(p43,k);
r=r+cheng(p53,k); r=r+cheng(p63 ,k); r=r+cheng(p73 ,k); r=r+cheng(p83 ,k);
r=r+cheng(p93 ,k); r=r+cheng(p103 ,k);r=r+cheng(p113 ,k);r=r+cheng(p123 ,k);
r=r+cheng(p133 ,k);r=r+cheng(p143 ,k);r=r+cheng(p153 ,k);r=r+cheng(p163 ,k);
r=r+cheng(p173 ,k);r=r+cheng(p183 ,k);r=r+cheng(p193 ,k);r=r+cheng(p203 ,k);
r=r+cheng(p213 ,k);r=r+cheng(p223 ,k);r=r+cheng(p233 ,k);r=r+cheng(p243 ,k);
r=r+cheng(p14,k); r=r+cheng(p24,k); r=r+cheng(p34,k); r=r+cheng(p44,k);
r=r+cheng(p54,k); r=r+cheng(p64 ,k); r=r+cheng(p74 ,k); r=r+cheng(p84 ,k);
r=r+cheng(p94 ,k); r=r+cheng(p104 ,k);r=r+cheng(p114 ,k);r=r+cheng(p124 ,k);
r=r+cheng(p134 ,k);r=r+cheng(p144 ,k);r=r+cheng(p154 ,k);r=r+cheng(p164 ,k);
r=r+cheng(p174 ,k);r=r+cheng(p184 ,k);r=r+cheng(p194 ,k);r=r+cheng(p204 ,k);
r=r+cheng(p214 ,k);r=r+cheng(p224 ,k);r=r+cheng(p234 ,k);r=r+cheng(p244 ,k);
r=r+cheng(p15,k); r=r+cheng(p25,k); r=r+cheng(p35,k); r=r+cheng(p45,k);
r=r+cheng(p55,k); r=r+cheng(p65 ,k); r=r+cheng(p75 ,k); r=r+cheng(p85 ,k);
r=r+cheng(p95 ,k); r=r+cheng(p105 ,k);r=r+cheng(p115 ,k);r=r+cheng(p125 ,k);
r=r+cheng(p135 ,k);r=r+cheng(p145 ,k);r=r+cheng(p155 ,k);r=r+cheng(p165 ,k);
r=r+cheng(p175 ,k);r=r+cheng(p185 ,k);r=r+cheng(p195 ,k);r=r+cheng(p205 ,k);
r=r+cheng(p215 ,k);r=r+cheng(p225 ,k);r=r+cheng(p235 ,k);r=r+cheng(p245 ,k);
return(r);}
main()
{int i,j;
float m=0.0,z1,z2,z3,z4,z5,x1,x2,x3,x4,x5;
float w1[7],w2[7],w3[7],w4[7],w5[7],k[6][6];
for(i=1;i<=6;i++)
scanf("%f",&w1[i]);printf("\n");
for(i=1;i<=6;i++)
scanf("%f",&w2[i]);printf("\n");
for(i=1;i<=6;i++)
scanf("%f",&w3[i]);printf("\n");
for(i=1;i<=6;i++)
scanf("%f",&w4[i]);printf("\n");
for(i=1;i<=6;i++)
scanf("%f",&w5[i]);printf("\n");
k[1][1]=w1[1]; k[1][2]=w1[2]; k[1][3]=w1[3]; k[1][4]=w1[4];k[1][5]=w1[5];
k[2][1]=w2[1]; k[2][2]=w2[2]; k[2][3]=w2[3]; k[2][4]=w2[4];k[2][5]=w2[5];
k[3][1]=w3[1]; k[3][2]=w3[2]; k[3][3]=w3[3]; k[3][4]=w3[4];k[3][5]=w3[5];
k[4][1]=w4[1]; k[4][2]=w4[2]; k[4][3]=w4[3]; k[4][4]=w4[4];k[4][5]=w4[5];
k[5][1]=w5[1]; k[5][2]=w5[2]; k[5][3]=w5[3]; k[5][4]=w5[4];k[5][5]=w5[5];
m=hang(k);
if(m==0) {printf("You can solve it easily!\nI do not help you.");
goto last;}
k[1][1]=w1[6]; k[1][2]=w1[2]; k[1][3]=w1[3]; k[1][4]=w1[4];k[1][5]=w1[5];
k[2][1]=w2[6]; k[2][2]=w2[2]; k[2][3]=w2[3]; k[2][4]=w2[4];k[2][5]=w2[5];
k[3][1]=w3[6]; k[3][2]=w3[2]; k[3][3]=w3[3]; k[3][4]=w3[4];k[3][5]=w3[5];
k[4][1]=w4[6]; k[4][2]=w4[2]; k[4][3]=w4[3]; k[4][4]=w4[4];k[4][5]=w4[5];
k[5][1]=w5[6]; k[5][2]=w5[2]; k[5][3]=w5[3]; k[5][4]=w5[4];k[5][5]=w5[5];
z1=hang(k);x1=z1/m;
k[1][1]=w1[1]; k[1][2]=w1[6]; k[1][3]=w1[3]; k[1][4]=w1[4];k[1][5]=w1[5];
k[2][1]=w2[1]; k[2][2]=w2[6]; k[2][3]=w2[3]; k[2][4]=w2[4];k[2][5]=w2[5];
k[3][1]=w3[1]; k[3][2]=w3[6]; k[3][3]=w3[3]; k[3][4]=w3[4];k[3][5]=w3[5];
k[4][1]=w4[1]; k[4][2]=w4[6]; k[4][3]=w4[3]; k[4][4]=w4[4];k[4][5]=w4[5];
k[5][1]=w5[1]; k[5][2]=w5[6]; k[5][3]=w5[3]; k[5][4]=w5[4];k[5][5]=w5[5];
z2=hang(k);x2=z2/m;
k[1][1]=w1[1]; k[1][2]=w1[2]; k[1][3]=w1[6]; k[1][4]=w1[4];k[1][5]=w1[5];
k[2][1]=w2[1]; k[2][2]=w2[2]; k[2][3]=w2[6]; k[2][4]=w2[4];k[2][5]=w2[5];
k[3][1]=w3[1]; k[3][2]=w3[2]; k[3][3]=w3[6]; k[3][4]=w3[4];k[3][5]=w3[5];
k[4][1]=w4[1]; k[4][2]=w4[2]; k[4][3]=w4[6]; k[4][4]=w4[4];k[4][5]=w4[5];
k[5][1]=w5[1]; k[5][2]=w5[2]; k[5][3]=w5[6]; k[5][4]=w5[4];k[5][5]=w5[5];
z3=hang(k);x3=z3/m;
k[1][1]=w1[1]; k[1][2]=w1[2]; k[1][3]=w1[3]; k[1][4]=w1[6];k[1][5]=w1[5];
k[2][1]=w2[1]; k[2][2]=w2[2]; k[2][3]=w2[3]; k[2][4]=w2[6];k[2][5]=w2[5];
k[3][1]=w3[1]; k[3][2]=w3[2]; k[3][3]=w3[3]; k[3][4]=w3[6];k[3][5]=w3[5];
k[4][1]=w4[1]; k[4][2]=w4[2]; k[4][3]=w4[3]; k[4][4]=w4[6];k[4][5]=w4[5];
k[5][1]=w5[1]; k[5][2]=w5[2]; k[5][3]=w5[3]; k[5][4]=w5[6];k[5][5]=w5[5];
z4=hang(k);x4=z4/m;
k[1][1]=w1[1]; k[1][2]=w1[2]; k[1][3]=w1[3]; k[1][4]=w1[4];k[1][5]=w1[6];
k[2][1]=w2[1]; k[2][2]=w2[2]; k[2][3]=w2[3]; k[2][4]=w2[4];k[2][5]=w2[6];
k[3][1]=w3[1]; k[3][2]=w3[2]; k[3][3]=w3[3]; k[3][4]=w3[4];k[3][5]=w3[6];
k[4][1]=w4[1]; k[4][2]=w4[2]; k[4][3]=w4[3]; k[4][4]=w4[4];k[4][5]=w4[6];
k[5][1]=w5[1]; k[5][2]=w5[2]; k[5][3]=w5[3]; k[5][4]=w5[4];k[5][5]=w5[6];
z5=hang(k);x5=z5/m;
printf("\nx1=%f\n\nx2=%f\n\nx3=%f\n\nx4=%f\n\nx5=%f\n",x1,x2,x3,x4,x5);
printf("\n\nAuthor: Cheng Fengming\n\nTime: 2006.9.13\n\nPlace: Qufu\n");
last:getch();}