Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.4 kB
3
Indexable
Never
#include <stdio.h>
#include <math.h>

struct triangle{
    struct coordinate{
        double x;
        double y;
    } point[3];
    double line[3];
    double circ;
};

void input(struct triangle *p){
    for (int i = 0; i < 3; i++){
        scanf("%lf", &(p->point[i].x));
        scanf("%lf", &(p->point[i].y));
    }
    p->line[0] = sqrt(pow(p->point[0].x - p->point[1].x, 2) + pow(p->point[0].y - p->point[1].y, 2));
    p->line[1] = sqrt(pow(p->point[1].x - p->point[2].x, 2) + pow(p->point[1].y - p->point[2].y, 2));
    p->line[2] = sqrt(pow(p->point[2].x - p->point[0].x, 2) + pow(p->point[2].y - p->point[0].y, 2));
}

int check(struct triangle p){
    if (p.line[0] > 0 && p.line[1] > 0 && p.line[2] > 0&& p.line[0] + p.line[1] > p.line[2] && p.line[1] + p.line[2] > p.line[0] && p.line[2] + p.line[0] > p.line[1]){
        return 1;
    }
    return 0;
}

int main(){
    int t;
    scanf("%d", &t);
    struct triangle p[t];
    for (int i = 0; i < t; i++){
        input(&p[i]);
        if (!check(p[i])){
            printf("INVALID\n");
        }
        else{
            float h = (p[i].line[0] + p[i].line[1] + p[i].line[2]) / 2;
            p[i].circ = sqrt(h * (h - p[i].line[0]) * (h - p[i].line[1]) * (h - p[i].line[2]));
            printf("%.2lf\n", p[i].circ);
        }
    }
   return 0;
}