Problem p00081 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define range(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define rep(i, n) range(i, 0, n)
using namespace std;

typedef long double D;
typedef complex<D> P;
typedef struct {
  P s, t;
} L;

const D eps = 1.0e-10;
const D pi = acos(-1.0);
template <class T> bool operator==(T a, T b) { return abs(a - b) < eps; }
template <class T> bool operator<(T a, T b) { return a < b - eps; }
template <class T> bool operator<=(T a, T b) { return a < b + eps; }
template <class T> int sig(T r) {
  return (r == 0 || r == -0) ? 0 : r > 0 ? 1 : -1;
}
template <class T> int sig(T a, T b = 0) { return a < b ? -1 : b > a ? 1 : 0; }
#define X real()
#define Y imag()

D ip(P a, P b) { return a.X * b.X + a.Y * b.Y; }
D ep(P a, P b) { return a.X * b.Y - a.Y * b.X; }
D sq(D a) { return sqrt(max(a, (D)0)); }
P vec(L l) { return l.t - l.s; }
inline P input() {
  D x, y;
  cin >> x >> y;
  return P(x, y);
}
//??\??? ???????????¬????????¨???

// ?°???± verify AOJ CGL_1_A
P proj(P b, P p) { return b * ip(b, p) / norm(b); }
P proj(L l, P p) { return l.s + proj(vec(l), p - l.s); }
// ????°? verify AOJ CGL_1_B
P refl(L l, P p) { return proj(l, p) * D(2.0) - p; }

int main(void) {
  while (1) {
    char tmp;
    double x, y;
    cin >> x >> tmp >> y;
    P a, b;
    a = {x, y};
    cin >> tmp >> x >> tmp >> y;
    b = {x, y};
    L base = {a, b};
    P point;
    cin >> tmp >> x >> tmp >> y;
    point = {x, y};
    P ans = refl(base, point);
    cout.precision(10);
    cout << fixed << ans.X << " " << ans.Y << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define range(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define rep(i, n) range(i, 0, n)
using namespace std;

typedef long double D;
typedef complex<D> P;
typedef struct {
  P s, t;
} L;

const D eps = 1.0e-10;
const D pi = acos(-1.0);
template <class T> bool operator==(T a, T b) { return abs(a - b) < eps; }
template <class T> bool operator<(T a, T b) { return a < b - eps; }
template <class T> bool operator<=(T a, T b) { return a < b + eps; }
template <class T> int sig(T r) {
  return (r == 0 || r == -0) ? 0 : r > 0 ? 1 : -1;
}
template <class T> int sig(T a, T b = 0) { return a < b ? -1 : b > a ? 1 : 0; }
#define X real()
#define Y imag()

D ip(P a, P b) { return a.X * b.X + a.Y * b.Y; }
D ep(P a, P b) { return a.X * b.Y - a.Y * b.X; }
D sq(D a) { return sqrt(max(a, (D)0)); }
P vec(L l) { return l.t - l.s; }
inline P input() {
  D x, y;
  cin >> x >> y;
  return P(x, y);
}
//??\??? ???????????¬????????¨???

// ?°???± verify AOJ CGL_1_A
P proj(P b, P p) { return b * ip(b, p) / norm(b); }
P proj(L l, P p) { return l.s + proj(vec(l), p - l.s); }
// ????°? verify AOJ CGL_1_B
P refl(L l, P p) { return proj(l, p) * D(2.0) - p; }

int main(void) {
  while (1) {
    char tmp;
    double x, y;
    cin >> x >> tmp >> y;
    if (cin.eof())
      break;
    P a, b;
    a = {x, y};
    cin >> tmp >> x >> tmp >> y;
    b = {x, y};
    L base = {a, b};
    P point;
    cin >> tmp >> x >> tmp >> y;
    point = {x, y};
    P ans = refl(base, point);
    cout.precision(10);
    cout << fixed << ans.X << " " << ans.Y << endl;
  }
  return 0;
}