题解 | #Grading#
Grading
https://www.nowcoder.com/practice/23e3244406724ffa8330760f640c8149
#include<cstdio>
int Abs(int x) {
if (x >= 0) {
return x;
} else {
return -x;
}
}
int MAX(int a, int b, int c) {
if (a >= b && a >= c) {
return a;
}
if (b >= a && b >= c) {
return b;
}
if (c >= a && c >= b) {
return c;
} else {
return 0;
}
}
int main() {
int P, T;
float G1, G2, G3, GJ;
while (scanf("%d%d%f%f%f%f", &P, &T, &G1, &G2, &G3, &GJ) != EOF) {
if (Abs(G1 - G2) <= T) {
printf("%.1f", (G1 + G2) / 2);
}
if (Abs(G1 - G2) > T && Abs(G3 - G2) <= T && Abs(G3 - G1) <= T) {
printf("%.1f", MAX(G1, G2, G3));
}
if (Abs(G1 - G2) > T && Abs(G3 - G2) <= T && Abs(G3 - G1) > T ||
Abs(G1 - G2) > T && Abs(G3 - G1) <= T && Abs(G3 - G2) > T) {
if ((Abs(G3 - G1) - Abs(G3 - G2)) >= 0) {
printf("%.1f", (G3 + G2) / 2);
}
}
if (Abs(G1 - G2) > T && Abs(G3 - G2) > T && Abs(G3 - G1) > T) {
printf("%.1f", GJ);
} else {
return 0;
}
}
}
