九度OJ 1002

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int abs(int n)
{
    return n < 0 ? -n : n;
}
int main()
{
    int p, t, g1, g2, g3, gj;
    double grade;
    while(cin >> p >> t >> g1 >> g2 >> g3 >> gj)
    {
        if(abs(g1 - g2) <= t)
        {
            grade = (g1 + g2) / 2.;
        }
        else if(abs(g3 - g2) <= t && abs(g3 - g1) > t)
        {
            grade = (g3 + g2) / 2.;
        }
        else if(abs(g3 - g1) <= t && abs(g3 - g2) > t)
        {
            grade = (g3 + g1) / 2.;
        }
        else if(abs(g3 - g1) <= t && abs(g3 - g2) <= t)
        {
            grade = max(g3, max(g1, g2));
        }
        else
        {
            grade = gj;
        }
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(1);
        cout << grade << endl;
    }
}

你可能感兴趣的:(九度OJ 1002)