UVA Solution 378 - Intersecting Lines - Solution in C, C++ | Volume 3 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Friday, May 5, 2017

UVA Solution 378 - Intersecting Lines - Solution in C, C++ | Volume 3

UVA Solution 378 - Intersecting Lines - Solution in C, C++ | Volume 3


UVA Online Judge Solution 378 - Intersecting Lines | Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=314

Problem Name: 378 - Intersecting Lines
Problem Number : UVA - 378 - Intersecting Lines
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus

UVA Solution 378 - Intersecting Lines - Solution in C, C++ | Volume 3

UVA Solution 378 - Intersecting Lines Code in C, CPP:


#include <stdio.h>
struct Point {
    int x, y;
};
struct Segment {
    Point s, e;
};
void solve(Segment a, Segment b) {
    int a1, b1, c1, a2, b2, c2;
    int D, Dx, Dy;
    a1 = a.s.y-a.e.y, b1 = -a.s.x+a.e.x;
    a2 = b.s.y-b.e.y, b2 = -b.s.x+b.e.x;
    c1 = a1*a.s.x + b1*a.s.y;
    c2 = a2*b.s.x + b2*b.s.y;
    D = a1*b2-a2*b1;
    Dx = c1*b2 - c2*b1;
    Dy = a1*c2 - a2*c1;
    if(!D && (Dx || Dy))
        puts("NONE");
    else if(!D && !Dx && !Dy)
        puts("LINE");
    else
        printf("POINT %.2lf %.2lf\n", (double)Dx/D, (double)Dy/D);
}
int main() {
    int t;
    scanf("%d", &t);
    puts("INTERSECTING LINES OUTPUT");
    while(t--) {
        Segment a, b;
        scanf("%d %d %d %d", &a.s.x, &a.s.y, &a.e.x, &a.e.y);
        scanf("%d %d %d %d", &b.s.x, &b.s.y, &b.e.x, &b.e.y);
        solve(a, b);
    }
    puts("END OF OUTPUT");
    return 0;
}

No comments:

Post a Comment