Sort Triangle

 avatar
unknown
c_cpp
2 years ago
933 B
24
Indexable
#include <bits/stdc++.h>
#include <cstring>
#define f first
#define s second
#define ll long long

using namespace std;

struct Point {
    int x, y;    
};

double getLen(Point A, Point B) {
    return sqrt((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y));
}

struct Triangle {
    int id;
    Point A, B, C;
    
    double getPerimeter() {
        double ab = getLen(A, B);
        double ac = getLen(A, C);
        double bc = getLen(B, C);
        return (ab + ac + bc);
    }
};

Triangle t[100];

bool cmp(Triangle A, Triangle B) {
    return (A.getPerimeter() > B.getPerimeter());
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        t[i].id = i;
        cin >> t[i].A.x >> t[i].A.y;
        cin >> t[i].B.x >> t[i].B.y;
        cin >> t[i].C.x >> t[i].C.y;
    }
    
    sort(t, t + n, &cmp);
    for (int i = 0; i < n; ++i) {
        cout << t[i].id << " ";
    }
    return 0;
}






Editor is loading...
Leave a Comment