#include<stdio.h>
#define POINT_COUNT 12
typedef struct _tagPoint{
int x;
int y;
} POINT;
void question1()
{
int i, j, count;
int flag;
POINT points[POINT_COUNT] = {{1,2},{3,4},{ 3,4 },{ 3,4 },
{ 3,4 },{ 5,4 } ,{ 3,4 } ,{ 3,4 } ,
{ 3,6 } ,{ 5,4 } ,{ 3,4 } ,{ 3,4 } };//自己换这些数据吧
POINT target[POINT_COUNT];
count = 0;
for(i = 0;i<POINT_COUNT;i++)
{
flag = 0;
for (j = 0; j < i; j++)
{
if (target[j].x == points[i].x && target[j].y == points[i].y)
{
flag = 1;
break;
}
}
if (flag != 1)
{
target[count].x = points[i].x;
target[count].y = points[i].y;
count++;
}
}
for (i = 0; i < count; i++)
{
printf("(%d,%d) ",target[i].x,target[i].y);
}
}
#define LINE_COUNT 6
typedef struct _tagLine {
int id;
int flag;
POINT p1;
POINT p2;
}LINE;
void question2()
{
LINE lines[LINE_COUNT] = {
{ 1,0, { 1,3 },{ 4,2 } },
{ 2,0, { 6,6 },{ 9,7 } },
{ 3,0, { 4,2 },{ 4,5 } },
{ 4,0, { 9,7 },{ 12,13 }},
{ 5,0, { 12,13 },{ 13,14 } },
{ 6,0, { 4,5 },{ 6,6 } },
};
int order[LINE_COUNT]; //按线的连接顺序保存线在 lines 数组下标
int last = 0;//已经保存的下标数
int i ;
int found;
order[last] = 0;//第一条线的下标
lines[0].flag = 1; //下标已经保存了
while(1)
{
found = 0;
for (i = 0; i < LINE_COUNT; i++)
{
if (lines[i].flag == 0 &&
lines[order[last]].p2.x == lines[i].p1.x &&
lines[order[last]].p2.y == lines[i].p1.y)
{
found = 1;
last++;
order[last] = i;
lines[i].flag = 1;
break;
}
}
if (found == 0)
{
break;
}
}
for (i = 0; i <= last; i++)
{
printf("Line ID:%d ((%-3d,%-3d),(%-3d,%-3d))\r\n",
lines[order[i]].id,
lines[order[i]].p1.x,
lines[order[i]].p1.y,
lines[order[i]].p2.x,
lines[order[i]].p2.y);
}
}
int main()
{
question1();
printf("\r\n");
question2();
return 0;
}