Language: C++

#include <vector>
#include <cmath>

const double EPSILON = 1e-10;

inline bool equals(double a, double b) {
    return std::fabs(a - b) < EPSILON;
}

struct Point {
    double x;
    double y;

    bool operator < (const Point& p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point& p) const {
        return equals(x, p.x) && equals(y, p.y);
    }
};

Point operator + (const Point& p1, const Point& p2) {
    return Point{p1.x + p2.x, p1.y + p2.y};
}

Point operator - (const Point& p1, const Point& p2) {
    return Point{p1.x - p2.x, p1.y - p2.y};
}

Point operator * (const Point& p1, double k) {
    return Point{p1.x * k, p1.y * k};
}

struct Segment {
    Point p1, p2;
};

struct Circle {
    Point center;
    double radius;
};

using Vector = Point;
using Line = Segment;
using Polygon = std::vector<Point>;


double norm(const Vector& p) {
    return p.x * p.x + p.y + p.y;
}

double abs(const Vector& p) {
    return std::sqrt(norm(p));
}

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

double cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x;
}


Vector projection(const Segment& s, const Point& p) {
    Vector base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / norm(base);
    return s.p1 + base * r;
}

Vector reflection(const Segment& s, const Point& p) {
    auto proj = projection(s, p);
    return p + (projection(s, p) - p) * 2.0;
}

bool is_orthogonal(const Vector& a, const Vector& b) {
    return equals(dot(a, b), 0.0);
}

bool is_orthogonal(const Segment& s1, const Segment& s2) {
    return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

bool is_parallel(const Vector& a, const Vector& b) {
    return equals(cross(a, b), 0.0);
}

bool is_parallel(const Segment& s1, const Segment& s2) {
    return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

enum {
    COUNTER_CLOCKWISE = 1;
    CLOCKWISE = -1;
    ONLINE_BACK = 2;
    ONLINE_FRONT = -1;
    ON_SEGMENT = 0;
}

int ccw(const Point& p0, const Point& p1, const Point& p2) {
    auto a = p1 - p0;
    auto b = p2 - p0;
    if (cross(a, b) > EPSILON) return COUNTER_CLOCKWISE;
    if (cross(a, b) < -EPSILON) return CLOCKWISE;
    if (dot(a, b) < -EPSILON) return ONLINE_BACK;
    if (norm(a) < norm(b)) return ONLINE_FRONT;
    return ON_SEGMENT;
}

double intersect(const Point& p1, const Point& p2, const Point& p3, const Point& p4) {
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
            ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

double intersect(const Segment& s1, const Segment& s2) {
    return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

double distance(const Point& a, const Point& b) {
    return abs(a - b);
}

double distanceLP(const Line& l, const Point& p) {
    return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}

double distanceSP(const Segment& s1, const Point& s2) {
    if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p - s.p1);
    if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p - s.p2);
    return distanceLP(s, p);
}

double distance(const Segment& s1, const Segment& s2) {
    if (intersect(s1, s2)) return 0.0;
    return min(min(distanceSP(s1, s2.p1), distanceSP(s1, s2.p2)),
               min(distanceSP(s2, s1.p1), distanceSP(s2, s1.p2)));
}


#include <iostream>
#include <iomanip>
#include <array>

using namespace std;

int main() {
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        array<Point, 4> points;
        for (auto& p : points) {
            cin >> p.x >> p.y;
        }
        Segment s1{points[0], points[1]};
        Segment s2{points[2], points[3]};
        cout << distance(s1, s2) << endl;
    }

    return 0;
}


Compiler output:
a.cc:94:26: error: expected '}' before ';' token
   94 |     COUNTER_CLOCKWISE = 1;
      |                          ^
a.cc:93:6: note: to match this '{'
   93 | enum {
      |      ^
a.cc:95:5: error: 'CLOCKWISE' does not name a type
   95 |     CLOCKWISE = -1;
      |     ^~~~~~~~~
a.cc:96:5: error: 'ONLINE_BACK' does not name a type
   96 |     ONLINE_BACK = 2;
      |     ^~~~~~~~~~~
a.cc:97:5: error: 'ONLINE_FRONT' does not name a type
   97 |     ONLINE_FRONT = -1;
      |     ^~~~~~~~~~~~
a.cc:98:5: error: 'ON_SEGMENT' does not name a type
   98 |     ON_SEGMENT = 0;
      |     ^~~~~~~~~~
a.cc:99:1: error: expected declaration before '}' token
   99 | }
      | ^
a.cc: In function 'int ccw(const Point&, const Point&, const Point&)':
a.cc:105:40: error: 'CLOCKWISE' was not declared in this scope
  105 |     if (cross(a, b) < -EPSILON) return CLOCKWISE;
      |                                        ^~~~~~~~~
a.cc:106:38: error: 'ONLINE_BACK' was not declared in this scope
  106 |     if (dot(a, b) < -EPSILON) return ONLINE_BACK;
      |                                      ^~~~~~~~~~~
a.cc:107:35: error: 'ONLINE_FRONT' was not declared in this scope
  107 |     if (norm(a) < norm(b)) return ONLINE_FRONT;
      |                                   ^~~~~~~~~~~~
a.cc:108:12: error: 'ON_SEGMENT' was not declared in this scope
  108 |     return ON_SEGMENT;
      |            ^~~~~~~~~~
a.cc: In function 'double distanceSP(const Segment&, const Point&)':
a.cc:129:13: error: 's' was not declared in this scope; did you mean 's1'?
  129 |     if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p - s.p1);
      |             ^
      |             s1
a.cc:129:26: error: 'p' was not declared in this scope
  129 |     if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p - s.p1);
      |                          ^
a.cc:130:13: error: 's' was not declared in this scope; did you mean 's1'?
  130 |     if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p - s.p2);
      |             ^
      |             s1
a.cc:130:26: error: 'p' was not declared in this scope
  130 |     if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p - s.p2);
      |                          ^
a.cc:131:23: error: 's' was not declared in this scope; did you mean 's1'?
  131 |     return distanceLP(s, p);
      |                       ^
      |                       s1
a.cc:131:26: error: 'p' was not declared in this scope
  131 |     return distanceLP(s, p);
      |                          ^
a.cc: In function 'double distance(const Segment&, const Segment&)':
a.cc:136:16: error: 'min' was not declared in this scope; did you mean 'std::min'?
  136 |     return min(min(distanceSP(s1, s2.p1), distanceSP(s1, s2.p2)),
      |                ^~~
      |                std::min
In file included from /usr/include/c++/14/vector:62,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: 'std::min' declared here
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
a.cc:136:12: error: 'min' was not declared in this scope; did you mean 'std::min'?
  136 |     return min(min(distanceSP(s1, s2.p1), distanceSP(s1, s2.p2)),
      |            ^~~
      |            std::min
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: 'std::min' declared here
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~