马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
int calc(float e,float f,float g,float h)
{
int i,j,k;
double result1,result2,result3;
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<4;j++)
{
switch(j)
{
case 0:result2=g+result1;break;
case 1:result2=g-result1;break;
case 2:result2=g*result1;break;
default:result2=g/result1;
}
for(k=0;k<4;k++)
{
switch(k)
{
case 0:result3 = h + result2;break;
case 1:result3 = h - result2;break;
case 2:result3 = h * result2;break;
default:result3 = h / result2;
}
if((result3>23.5)&&(result3<24.5))
{
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++)
{
switch(l)
{
case 0:e = (float)a;break;
case 1:e = (float)b;break;
case 2:e = (float)c;break;
default:e = (float)d;break;
}
for(m=0;m<4;m++)
{
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(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(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;
}题目地址
|