program Trinagle; uses Crt, Graph; const eps = 0.00001; {Погрешность} numP = 4; numT = 4; type tPoint = record x, y: real; end; tTriangle = record a, b, c: tPoint; end; var Points : array[1..numP] of tPoint; Triangles : array[1..numT] of integer; table : array[1..numT] of tTriangle; inF : text; i, j, k : integer; p, p1, p2, p3: tPoint; c, s, d: integer; GrDriver, GrMode, GrError : integer; equal: Boolean; procedure OpenFile(var f:text); var Name: string; Err: integer; begin repeat WriteLn('Введите имя файла...'); ReadLn(name); Assign(f, Name); {$i-} Reset(f); {$i+} Err:= IOResult; if Err <> 0 then writeln('Файл не найден...'); until Err = 0; writeln('Файл открыт успешно...') end; procedure InputDots(var f: text); var i: integer; begin for i:= 1 to numP do ReadLn(f, points[i].x, points[i].y) end; function EqPoints(a, b: tPoint): Boolean; {Равенство двух точек} begin EqPoints:= (abs(a.x - b.x) < eps) and (abs(a.y - b.y) < eps) end; function Includ(var a, b, c: tPoint): Boolean; {Проверка принадлежности} var {точки отрезку} p: real; begin if ((b.x - c.x) < 0) and (not EqPoints(c, b)) then p:= (a.x - c.x)/(b.x - c.x) else p:= 1 + 1; Includ:= (0 <= p) and (p <= 1) and (abs((p*b.y + (1 - p)*c.y) - a.y) < eps) end; procedure DrawDots; var i : integer; num: string; begin for i:= 1 to numP do begin Circle(Round(points[i].x), Round(points[i].y), 2); Str(i, Num); OutTextXY(Round(points[i].x) + 4, Round(points[i].y) + 3, Num) end; end; procedure DrawTri(a, b, c: tPoint); begin Line(round(a.x), round(a.y), round(b.x), round(b.y)); Line(round(b.x), round(b.y), round(c.x), round(c.y)); Line(round(c.x), round(c.y), round(a.x), round(a.y)) end; procedure FindMaxTri(var mass: array of integer); var max: integer; begin max:= mass[1]; for i:= 1 to k do if mass[i] > max then max:= i; DrawTri(table[i].a, table[i].b, table[i].c); end; begin OpenFile(inF); {Открытие файла} InputDots(inF); s:= 0; {Построение множества всех треугольников} for i:= 1 to numP do for j:= 1 to numP do for k:= 1 to numP do begin p1.x:= points[i].x; p1.y:= points[i].y; p2.x:= points[j].x; p2.y:= points[j].y; p3.x:= points[k].x; p3.y:= points[k].y; c:= 0; for d:= 1 to numP do begin p:= points[d]; equal:= (d = i) or (d = j) or (d = k); if not equal then begin table[s].a:= p1; table[s].b:= p2; table[s].c:= p3; if Includ(p, p1, p2) or Includ(p, p1, p3) or Includ(p, p2, p3) then c:= c + 1 end; end; s:= s + 1; triangles[s]:= c end; {Инициализация графики} GrDriver:= Detect; InitGraph(GrDriver, GrMode, 'C:\TP\BGI'); GrError:= GraphResult; if GrError <> GrOk then begin WriteLn('Ошибка инициализации графики'); Halt end; {Рисование} DrawDots; {Рисование точек} ReadLn; FindMaxTri(triangles); ReadLn; CloseGraph end.