Cod sursa(job #2276565)

Utilizator DonCiprianoAmzuloiu Andrei-Ciprian DonCipriano Data 4 noiembrie 2018 21:09:06
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <fstream>

using namespace std;

typedef struct
{
    int x;
    int y;
} point;

float findM(point a, point b)
{
    return (float) (b.y - a.y) / (b.x - a.x);
}

int main()
{
    int noPoints;
    point p[1000];

    float m1;
    float m2;

    int noResults = 0;

    ifstream fin("trapez.in");

    fin >> noPoints;

    for(int i = 0; i < noPoints; i++)
    {
        fin >> p[i].x;
        fin >> p[i].y;
    }

    fin.close();

    for(int i = 0; i < noPoints; i++)
    {
        for(int j = 0; j < noPoints; j++)
        {
            if(i == j) continue;

            m1 = findM(p[i], p[j]);

            for(int k = 0; k < noPoints; k++)
            {
                for(int l = 0; l < noPoints; l++)
                {
                    if(k == l) continue;
                    if( (k == i && l == j) || (k == j && l == i)) continue;

                    m2 = findM(p[k], p[l]);

                    if(m1 == m2) noResults++;
                }
            }
        }
    }

    ofstream fout("trapez.out");
    fout << noResults;
    fout.close();

    return 0;
}