title: Find Middle points(Computational geometry c++)
body: <p>This program should read for input an integer N then the x and y coordinates of the N points
  and return the number of points that are the middle points of any two other points in the set.
  First the program stores the points in an array then we loop throgh the points and calculate the distance between points[i] and every other point. We sort the points according to that distance then if we find that any two points have the same distance we check if point[i] is aligned with them if it is the case we store point[i] in the middles list.
  We then get rid of doubles in the list and return the size of the list.
  I submitted my solution and it doesn't work for all the cases. Please help: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include &lt;algorithm&gt;
  #include &lt;list&gt;
  #include &lt;stdio.h&gt;
  
  using namespace std;
  
  struct Point
  {
      int x;
      int y;
      int distance;
  };
  bool PointSort(Point a,Point b);
  bool colinear(Point a,Point b,Point c);
  bool same_point (Point first, Point second);
  int main()
  {
      list&lt;Point&gt; middles;
      int N;scanf("%d", &amp;N);
      Point points[N];
      Point points2[N];
      for(int i=0;i&lt;N;i++)
      {   scanf("%d", &amp;points[i].x);
          scanf("%d", &amp;points[i].y);
          points2[i].x=points[i].x;
          points2[i].y=points[i].y;
  
      }
      for(int i=0;i&lt;N;i++)
      {
           for(int j=0;j&lt;N;j++)
           {
              points2[j]=points[j];
           }
           for(int j=0;j&lt;N;j++)
           {
  
              points2[j].distance=(points[i].x-points2[j].x)*(points[i].x-    points2[j].x)+(points[i].y-points2[j].y)*(points[i].y-points2[j].y);
  
           }
           sort(points2,points2+N,&amp;PointSort);
           for(int j=0;j&lt;N;j++)
           {
  
              int k=j+1;
              while(points2[j].distance==points2[k].distance)
              {
  
                   bool coli=colinear(points[i],points2[j],points2[k]);
                   if(coli){middles.push_back(points2[i]);}
                   k++;
              }
           }
       }
      middles.unique(same_point);
      cout&lt;&lt;middles.size();
  
  
  }
  bool PointSort(Point a,Point b)
  {
      return a.distance&lt;b.distance;
  }
  bool colinear(Point a,Point b,Point c)
  {
      return (a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y))/2.0==0.0;
  } 
  bool same_point (Point first, Point second)
  { return (first.x==second.x &amp;&amp; first.y==second.y) ; }
  </code></pre>