|
楼主 |
发表于 2015-6-5 22:58:56
|
显示全部楼层
本帖最后由 Prolearning 于 2015-6-5 23:00 编辑
#include <stdio.h>
int calc(float e,float f,float g,float h)
{
int i,j,k;
double result1,result2,result3,result4,result5,result6;
for(i=0;i<4;i++)
{
switch(i)
{
case 0:result1=e+f;break;
case 1:result1=e-f;break;
case 2:result1=e*f;break;
default:result1=e/f;
}
for(j=0;j<6;j++)
{
switch(j)
{
case 0:result2 = g+result1;break;
case 1:result2 = result1-g;break;
case 2:result2 = g*result1;break;
case 3:result2 = g-result1;break;
case 4:result2 = g/result1;break;
default:result2 = result1 / g;
}
for(k=0;k<6;k++)
{
switch(k)
{
case 0:result3 = h + result2;break;
case 1:result3 = result2 - h;break;
case 2:result3 = h * result2;break;
case 3:result3 = h - result2;break;
case 4:result3 = h / result2;break;
default:result3 = result2 / h;
}
if((result3>23.9)&&(result3<24.1))
{
return 1;
}
}
}
}
for(i=0;i<4;i++)
{
switch(i)
{
case 0:result4=e+f;break;
case 1:result4=e-f;break;
case 2:result4=e*f;break;
default:result4=e/f;
}
for(j=0;j<4;j++)
{
switch(j)
{
case 0:result5=g+h;break;
case 1:result5=h-g;break;
case 2:result5=g*h;break;
default:result5=h / g;
}
for(k=0;k<6;k++)
{
switch(k)
{
case 0:result6 = result4 + result5;break;
case 1:result6 = result4 - result5;break;
case 2:result6 = result4 * result5;break;
case 3:result6 = result5 - result4;break;
case 4:result6 = result5 / result4;break;
default:result6 = result4 / result5;
}
if((result6>23.9)&&(result6<24.1))
{
return 1;
}
}
}
}
return 0;
}
int main(int argc, char *argv[])
{
int a,b,c,d;
float e,f,g,h;
int l,m,n,o,flag;
while (scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
{
flag=0;
for(l=0;l<4;l++)
{
if(flag == 1) break;
switch(l)
{
case 0:e = (float)a;break;
case 1:e = (float)b;break;
case 2:e = (float)c;break;
default:e = (float)d;
}
for(m=0;m<4;m++)
{
if (1 == flag)
{
break;
}
if(m == l) continue;
else
{
switch(m)
{
case 0:f = (float)a;break;
case 1:f = (float)b;break;
case 2:f = (float)c;break;
default:f = (float)d;
}
}
for(n=0;n<4;n++)
{
if (1==flag)
{
break;
}
if(n == l||n == m) continue;
else
{
switch(n)
{
case 0:g = (float)a;break;
case 1:g = (float)b;break;
case 2:g = (float)c;break;
default:g = (float)d;
}
}
for(o=0;o<4;o++)
{
if (1 == flag)
{
break;
}
if(o == l||o == m||o == n) continue;
else
{
switch(o)
{
case 0:h = (float)a;break;
case 1:h = (float)b;break;
case 2:h = (float)c;break;
default:h = (float)d;
}
}
flag = calc(e,f,g,h);
}
}
}
}
if(flag == 1) printf("Yes\n");
else printf ("No\n");
}
return 0;
}
能帮我看看嘛?麻烦你了大神!!我也是醉了。这题已成我心结了 |
|