读清题目,按要求往下写就可以了。
//Grading 浙大 2024/1/4 //http://t.cn/E9rDPSq #include <iostream> #include <math.h> using namespace std; int main() { float p,t,g1,g2,g3,gj; float grade; while (cin>>p>>t>>g1>>g2>>g3>>gj) { if(abs(g1-g2)<=t) grade=(g1+g2)/2; else if(abs(g1-g3)<=t&&abs(g2-g3)<=t) { if(g1>g2) grade=(g1>g3)?g1:g3; else grade=(g2>g3)?g2:g3; } else if(abs(g1-g3)<=t) grade=(g1+g3)/2; else if(abs(g2-g3)<=t) grade=(g2+g3)/2; else grade=gj; printf("%.1f\n",grade); } return 0; }