Umístnení souboru www.TrSek.com/zadania/subor_tr.pas{ SUBOR_TR.PAS }
{ Program vycita zo suboru Num_Tria.txt dlzky stran trojuholnikov. }
{ Zisti ci sa daju zostrojit a vysledok zapise do suboru Num_1.txt. }
{ }
{ Author: Juraj Pupak }
{ Date : 27.10.2006 http://www.trsek.com }
program Subor_Triangle;
uses crt;
Procedure ZapisSubor(subor : string; vytvor : Boolean; moj_text : string);
var
Tsubor : Text;
begin
Assign(Tsubor,subor);
IF vytvor = True THEN
begin
Rewrite(Tsubor);
end else
begin
Append(Tsubor);
end;
writeln(Tsubor,moj_text);
close(Tsubor);
end;
Function DaSaZostrojit(Pole : array of integer) : Boolean;
var
Is_Triangle : Boolean;
begin
If Pole[1] + Pole[2] > Pole[3] THEN
begin
If Pole[3] + Pole[2] > Pole[1] THEN
begin
IF Pole[3] + Pole[1] > Pole[2] THEN
begin
Is_Triangle := True;
end else
begin
Is_Triangle := False;
end;
end else
begin
Is_Triangle := False;
end;
end else
begin
Is_Triangle := False;
end;
DaSaZostrojit := Is_Triangle;
end;
var
Tsubor : Text;
dlzka_retazca : integer;
index,number_1,Code : integer;
Cstr_Num,number : string;
Pole : array [0..3] of integer;
Is_Triangle,Vytvor : Boolean;
begin
clrscr;
writeln('Program vycita zo suboru Num_Tria.txt dlzky stran trojuholnikov.');
writeln('Zisti ci sa daju zostrojit a vysledok zapise do suboru Num_1.txt.');
while not Eof(Tsubor) Do
begin
Readln(Tsubor,Cstr_Num);
dlzka_retazca := length(Cstr_Num);
For index := 1 To dlzka_retazca Do
begin
number := copy(Cstr_Num,index,1);
Val(number,number_1,Code);
Pole[index] := number_1;
end;
Is_Triangle := DaSaZostrojit(Pole);
IF Is_Triangle = True THEN
begin
ZapisSubor('Num_1.txt',Vytvor,Cstr_Num);
Vytvor := False;
end;
end;