平面上的点

来源:互联网 发布:c语言玫瑰花数 编辑:程序博客网 时间:2024/06/10 00:01
#include<stdio.h>
#include<math.h>
const int maxn = 102;
struct Node{
int x;
int y;
};


Node nodes[maxn];


int max(int a, int b)
{
return a > b ? a : b;
}


main()
{
int n;
int i, j, k;
int num1, num2;
int x1, y1, x2, y2, x3, y3;
int a = 0, b;
while((scanf("%d", &n)) != EOF)
{
for(i = 0; i < n; i++)
{
   scanf("%d %d", &nodes[i].x, &nodes[i].y);
}
if(n < 3)
{
printf("%d", n);
continue;

for(i = 0; i < n; i++)
{    
    
x1 = nodes[i].x;
y1 = nodes[i].y;
for(j = i+1; j < n; j++)
{
    b = 2;
    x2 = nodes[j].x;
    y2 = nodes[j].y;
    if(x2 == x1 && y2 == y1)
    {
    b = 3;
    j++;
}
for(k = j+1; k < n; k++)
{
x3 = nodes[k].x;
y3 = nodes[k].y;
   num1 = (y3-y1) * (x2 - x1);
 
num2 = (y2 -y1) * (x3 - x1);
if(num1 == num2)
{
          b++;
}
}
  a = max(a,b);
}

}
printf("%d", a);
}

return 0;
}
0 0