Language: C++

#include <iostream>
#include <vector>
#include <cmath>

#define x first
#define y second

using namespace std;
typedef pair<double, double> pt;
const double e = 1e-8;
const double X = 1e4 + 1;

pt operator-(pt a, pt b) {
    return pt(a.x - b.x, a.y - b.y);
}

bool zero(double x) {
  return fabs(x) <= e;
}

bool le(double x, double y) {
  return x < y or fabs(x - y) <= e;
}

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

bool ccw(pt a, pt b, pt c) {
  double c = cross(b - a, c - a);
  return zero(c) or c > 0;
}

double sq(double d) {
  return d * d;
}

double dist(pt A, pt B) {
  return sqrt(sq(A.x - B.x) + sq(A.y - B.y));
}

bool intersect(pt A, pt B, pt C, pt D) {
  return ccw(A, B, C) != ccw(A, B, D) and ccw(C, D, A) != ccw(C, D, B);
}

bool on_line(pt A, pt B, pt C) {
  return fabs(dist(A, C) + dist(B, C) - dist(A, B)) <= e;
}

/*
bool on_line(pt A, pt B, pt C) {
  auto lower_x = min(A.x, B.x);
  auto upper_x = max(A.x, B.x);
  auto lower_y = min(A.y, B.y);
  auto upper_y = max(A.y, B.y);
  return (
      C.x >= lower_x
      and C.x <= upper_x
      C.x >= lower_x
      and C.x <= upper_x

}
*/

int contains(vector<pt> shape, pt C) {

  int intersections = 0;
  bool on_segment = false;
  pt D = {C.x, X};

  for (int i = 0; i < shape.size(); i++) {

    pt A = shape[i];
    pt B = shape[(i + 1) % shape.size()];

    bool j = intersect(A, B, C, D);
    intersections += j;
    on_segment |= on_line(A, B, C);
    /*
    printf("(%.0f %.0f) - (%.0f %.0f): (%.1f %.1f) = %d\n",
        A.x, A.y, B.x, B.y, C.x, C.y, j
    );
    */
  }

  if (on_segment) return 1;
  else if (intersections % 2 == 0) return 0;
  else return 2;

}

int main() {

  vector<pt> shape;

  int g;
  cin >> g;
  for (int i = 0; i < g; ++i) {
    double x, y;
    cin >> x >> y;
    shape.emplace_back(x, y);
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    double x, y;
    cin >> x >> y;
    cout << contains(shape, {x, y}) << endl;
  }

  return 0;
}



Compiler output:
a.cc: In function 'bool ccw(pt, pt, pt)':
a.cc:30:10: error: declaration of 'double c' shadows a parameter
   30 |   double c = cross(b - a, c - a);
      |          ^
a.cc:29:25: note: 'pt c' previously declared here
   29 | bool ccw(pt a, pt b, pt c) {
      |                      ~~~^
a.cc:30:29: error: no match for 'operator-' (operand types are 'double' and 'pt' {aka 'std::pair<double, double>'})
   30 |   double c = cross(b - a, c - a);
      |                           ~ ^ ~
      |                           |   |
      |                           |   pt {aka std::pair<double, double>}
      |                           double
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:30:31: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'double'
   30 |   double c = cross(b - a, c - a);
      |                               ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:30:31: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'double'
   30 |   double c = cross(b - a, c - a);
      |                               ^
a.cc:13:4: note: candidate: 'pt operator-(pt, pt)'
   13 | pt operator-(pt a, pt b) {
      |    ^~~~~~~~
a.cc:13:17: note:   no known conversion for argument 1 from 'double' to 'pt' {aka 'std::pair<double, double>'}
   13 | pt operator-(pt a, pt b) {
      |              ~~~^