九度1002 Grading/********************************* * 日期:2012-6-23 * 作者:SJF0115 * 题号: 九度1002 * 题目:Grading * 结果:AC * 题意: * 总结:**********************************/#include<stdio.h>#include<math.h>int main(){int P,T,G1,G2,G3,GJ;double Grade;while(scanf("%d %d %d %d %d %d",&P,&T,&G1,&G2,&G3,&GJ)!=EOF){if((G1>P||G1<0)||(G2>P||G2<0)||(G3>P||G3<0)||(GJ>P||GJ<0)){break;}if(fabs(G1-G2)<=T){Grade = (double)(G1 + G2)/2.0;}else{//G3 is within the tolerance with both G1 and G2if(fabs(G1-G3)<=T&&fabs(G2-G3)<=T){if(G1>G2){if(G1>G3){Grade = G1;}else{Grade = G3;}}else{if(G2>G3){Grade = G2;}else{Grade = G3;}}}//G3 is within the tolerance with neither G1 nor G2else if(fabs(G1-G3)>T&&fabs(G2-G3)>T){Grade = GJ;}//G3 is within the tolerance with either G1 or G2, but NOT bothelse{if(fabs(G3 - G1) > fabs(G3 - G2)){Grade = (double)(G2 + G3)/2.0;}else{Grade = (double)(G1 + G3)/2.0;}}}printf("%.1lf\n",Grade);}return 0;}