dimanche 26 janvier 2020

Which element of this code is not acceptable by SPOJ?

#include <iostream>
#include <cmath>

using namespace std;

double a, b, c, d, e, result, A, B, C, D, E, found, tests;

int main()
{
    cin >> tests;

    for (int i = 1; i <= tests; i++)
    {
        cin >> a >> b >> c >> d >> e;

        result = (a + b + c + d + e) / 5;

        A = fabs(result - a);
        B = fabs(result - b);
        C = fabs(result - c);
        D = fabs(result - d);
        E = fabs(result - e);

        // Five lines above shows calculations, which result in the compareable values.

        found = A;
        if (found >= B) found = B;
        if (found >= C) found = C;
        if (found >= D) found = D;
        if (found >= E) found = E;

        // Here I check, which value is the greatest.

        if (found == A)
            cout << a << endl;

        if (found == B)
            cout << b << endl;

        if (found == C)
            cout << c << endl;

        if (found == D)
            cout << d << endl;

        if (found == E)
            cout << e << endl;

        // And I return the value we are searching for.
    }

    return 0;
}

Here is the code I made for problem with this ID: 1102 on SPOJ. I don't know what's wrong, although it may be rivial, because the code is working outside of this webiste. I have made it as readable as I could, so I hope you can help.

Aucun commentaire:

Enregistrer un commentaire