题目来源:http://ac.jobdu.com/problem.php?pid=1002
看懂题意~~
我的代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int max(int a,int b,int c)
{int m;
m=a;
if(b>m)m=b;
else if(c>m)m=c;
return m;
}
int main()
{int p,t,g1,g2,g3,gj;
float avg;
while(scanf("%d%d%d%d%d%d",&p,&t,&g1,&g2,&g3,&gj)!=EOF)
{if(abs(g1-g2)<=t)avg=1.0/2*(g1+g2);
else {
if(((abs(g3-g1)<=t)&&(abs(g3-g2)>t))||((abs(g3-g2)<=t)&&(abs(g3-g1)>t)))
{if(abs(g3-g2)>=abs(g3-g1))avg=1.0/2*(g3+g1);
else avg=1.0/2*(g3+g2);
}
else if((abs(g3-g1)<=t)&&(abs(g3-g2)<=t))avg=max(g1,g2,g3);
else avg=gj;
}
printf("%.1f\n",avg);
}
return 0;
}