Problem p00068 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define EPS (1e-10)
using namespace std;

class Point {
public:
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
  Point operator+(Point &p) { return Point(x + p.x, y + p.y); }
  Point operator-(Point &p) { return Point(x - p.x, y - p.y); }
  Point operator*(double k) { return Point(x * k, y * k); }
  bool operator<(const Point &p) const {
    if (x == p.x)
      return y < p.y;
    else
      return x < p.x;
  }
};

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

int main() {
  int i, j, n, x, y, k;
  Point p[100];
  vector<Point> convex, c2;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%lf,%lf", &p[i].x, &p[i].y);
    }
    sort(p, p + n);

    convex.push_back(p[0]);
    convex.push_back(p[1]);

    j = 2;
    if (n > 3) {
      for (i = 2; i < n; i++) {
        Point a = convex[j - 1] - convex[j - 2];
        Point b = p[i] - convex[j - 2];
        while (cross(a, b) > EPS && j >= 2) {
          convex.pop_back();
          j--;
          if (j >= 2) {
            a = convex[j - 1] - convex[j - 2];
            b = p[i] - convex[j - 2];
          }
        }
        convex.push_back(p[i]);
        j++;
      }

      c2.push_back(p[n - 1]);
      c2.push_back(p[n - 2]);
      k = 2;
      for (i = n - 3; i >= 0; i--) {
        Point a = c2[k - 1] - c2[k - 2];
        Point b = p[i] - c2[k - 2];
        while (cross(a, b) > EPS && k >= 2) {
          c2.pop_back();
          k--;
          if (k >= 2) {
            a = c2[k - 1] - c2[k - 2];
            b = p[i] - c2[k - 2];
          }
        }
        c2.push_back(p[i]);
        k++;
      }
    }
    cout << n - (j + k - 2) << endl;
    convex.clear();
    c2.clear();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define EPS (1e-10)
using namespace std;

class Point {
public:
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
  Point operator+(Point &p) { return Point(x + p.x, y + p.y); }
  Point operator-(Point &p) { return Point(x - p.x, y - p.y); }
  Point operator*(double k) { return Point(x * k, y * k); }
  bool operator<(const Point &p) const {
    if (x == p.x)
      return y < p.y;
    else
      return x < p.x;
  }
};

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

int main() {
  int i, j, n, x, y;
  Point p[100];
  vector<Point> convex;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (i = 0; i < n; i++)
      scanf("%lf,%lf", &p[i].x, &p[i].y);
    sort(p, p + n);

    convex.push_back(p[0]);
    convex.push_back(p[1]);

    j = 1;
    for (i = 2; i < n; i++) {
      Point a = convex[j] - convex[j - 1];
      Point b = p[i] - convex[j - 1];
      if (cross(a, b) > EPS) {
        convex.pop_back();
        i--;
        j--;
      } else {
        convex.push_back(p[i]);
        j++;
      }
    }

    convex.push_back(p[n - 2]);
    for (i = n - 3; i >= 0; i--) {
      Point a = convex[j] - convex[j - 1];
      Point b = p[i] - convex[j - 1];
      if (cross(a, b) > EPS) {
        convex.pop_back();
        i++;
        j--;
      } else {
        convex.push_back(p[i]);
        j++;
      }
    }

    cout << n - (j + 1) << endl; // テδづつステδεつδ甘つ」1
    convex.clear();
  }
  return 0;
}