|
100鱼币
本帖最后由 Prolearning 于 2015-6-7 19:58 编辑
#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<6;i++)
{
switch(i)
{
case 0:result4=e+f;break;
case 1:result4=e-f;break;
case 2:result4=e*f;break;
case 3:result4=f/e;break;
case 4:result4=f-e;break;
default:result4=e/f;
}
for(j=0;j<6;j++)
{
switch(j)
{
case 0:result5=g+h;break;
case 1:result5=h-g;break;
case 2:result5=g*h;break;
case 3:result5=g-h;break;
case 4: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[])
{
float a,b,c,d;
float e,f,g,h;
int l,m,n,o,flag;
while (scanf("%f %f %f %f",&a,&b,&c,&d)!=EOF)
{
flag=0;
for(l=0;l<4;l++)
{
if(flag == 1) break;
switch(l)
{
case 0:e = a;break;
case 1:e = b;break;
case 2:e = c;break;
default:e = d;
}
for(m=0;m<4;m++)
{
if (1 == flag)
{
break;
}
if(m == l) continue;
else
{
switch(m)
{
case 0:f = a;break;
case 1:f = b;break;
case 2:f = c;break;
default:f = d;
}
}
for(n=0;n<4;n++)
{
if (1==flag)
{
break;
}
if(n == l||n == m) continue;
else
{
switch(n)
{
case 0:g = a;break;
case 1:g = b;break;
case 2:g = c;break;
default:g = 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 = a;break;
case 1:h = b;break;
case 2:h = c;break;
default:h = d;
}
}
flag = calc(e,f,g,h);
}
}
}
}
if(flag == 1) printf("Yes\n");
else printf ("No\n");
}
return 0;
}
题目地址为:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1600要改成能提交才行。
try this:
#include <stdio.h>
double result1,result2,result3;
int calc(float e,float f,float g,float h)
//int calc(int e,int f,int g,int h)
{
int i,j,k;
for(i=0;i<6;i++)
{
switch(i)
{
case 0:result1=e+f;break;
case 1:result1=e-f;break;
case 2:result1=e*f;break;
case 3:result1=f-e;break;
case 4:if(f!=0){result1=e/f;}break;
default:if(e!=0){result1=f/e;};
}
for(j=0;j<6;j++)
{
switch(j)
{
case 0:result2=g+result1;break;
case 1:result2=g-result1;break;
case 2:result2=g*result1;break;
case 3:result2=result1-g;break;
case 4:if(result1!=0){result2=g/result1;}break;
default:if(g!=0){result2=result1/g;};
}
for(k=0;k<6;k++)
{
switch(k)
{
case 0:result3 = h + result2;break;
case 1:result3 = h - result2;break;
case 2:result3 = h * result2;break;
case 3:result3 = result2 - h;break;
case 4:if(result2!=0){result3 = h / result2;}break;
default:if(h!=0){result3 = result2 / h;};
}
// if((result3>23.9)&&(result3<24.1)||(result3==24.00))
// if((result3>23.5)&&(result3<24.5))
if(result3==24.00)
{
return 1;
break;
}
}
}
}
return 0;
}
int main(int argc, char *argv[])
{
int a,b,c,d;
float e,f,g,h;
int l,m,n,o,flag;
int countx;
while (scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
{
flag=0;
countx =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 == 0) {countx=countx+0;}
if(flag == 1) {countx=countx+1;}
}
}
}
}
if (countx>0)printf("Yes!\n");
else printf("No!\n");
}
return 0;
}
|
最佳答案
查看完整内容
try this:
#include
double result1,result2,result3;
int calc(float e,float f,float g,float h)
//int calc(int e,int f,int g,int h)
{
int i,j,k;
for(i=0;i
|