|
[此贴子已经被作者于2005-12-8 18:31:11编辑过]
#include<stdio.h>
#include<math.h>
int N;
float date0[6]={84,6,10,8,10,2},date[6];
char ch0[5],ch[5];
void pro(int i,char chr)
{
int j;
switch(chr)
{
case '*':date[i]=date[i]*date[i+1];break;
case '/':date[i]=date[i]/date[i+1];break;
case '+':date[i]=date[i]+date[i+1];break;
case '-':date[i]=date[i]-date[i+1];break;
}
for(j=i;j<N-1;j++) ch[j]=ch[j+1];
i=i+1;
for(;i<N;i++) date[i]=date[i+1];
N=N-1;
}
void main()
{
int j1,j2,j3,j4,j5,j,yes,yes1,i;
char a[4]={'+','-','*','/'};
for(j1=0;j1<4;j1++)
{ch0[0]=a[j1];
for(j2=0;j2<4;j2++)
{ch0[1]=a[j2];
for(j3=0;j3<4;j3++)
{ch0[2]=a[j3];
for(j4=0;j4<4;j4++)
{ch0[3]=a[j4];
for(j5=0;j5<4;j5++)
{ch0[4]=a[j5];
for(j=0;j<5;j++) ch[j]=ch0[j];
for(j=0;j<6;j++) date[j]=date0[j];
N=5;
while(N!=0)
{
yes=1;i=0;
while((i<N)&&(yes))
{
if (ch[i]=='*') {pro(i,ch[i]);yes=0;break;}
if (ch[i]=='/') {pro(i,ch[i]);yes=0;break;}
i=i+1;
}
i=0;yes1=1;
if(yes)
while((i<N)&&(yes1))
{
if(ch[i]=='+') {pro(i,ch[i]);yes1=0;break;}
if(ch[i]=='-') {pro(i,ch[i]);yes1=0;break;}
i=i+1;
}
}
if(date[0]==50)
{ for(j=0;j<5;j++) {printf("%.0f",date0[j]);printf("%c",ch0[j]);}
printf("%.0f",date0[5]);printf("=50");
printf("\n");
}
}
}
}
}
}
}
运行结果 84*6/10-8/10/2=50