Treceți la conținutul principal

Prezentat

Forum 02.03.21 Tehnici de programare Limbajul Pascal

    • Tehnica Greedy -Statistica • Problema Comis Voiajerului • Metoda Backtraking Problema Reginelor • Turnuri de Hanoi • Tehnici de sortare metoda Bublesort • Metoda Trierii Pușculița

Greedy new statistica



Program Greedy;

var x,a,b,c:array[1..5000] of integer;
       s,s1,s2,s3:array[1..5000] of string[100];
i,j,k,l,n,m,p:integer;


function exista:boolean;
begin
exista:=false;
for i:=1 to n do begin
m:=m+1; 
if ((x[i]=0)and (m=n)) then  exista:=true; 
end; end;

procedure alegeelement;
begin
for i:=1 to n do begin
if ((X[i]>0) and (X[i]<=19)) then begin
j:=j+1; 
a[j]:=X[i]; s1[j]:=s[i]; x[i]:=0;
end;

if (X[i]>18) and (X[i]<=62) then begin
k:=k+1;
b[k]:=X[i]; s2[k]:=s[i]; x[i]:=0;
end;

if (X[i]>61) and (X[i]<=120) then begin
l:=l+1;
c[l]:=X[i]; s3[l]:=s[i]; x[i]:=0;
end; end; end;

procedure include;
begin
for i:=1 to n do begin
writeln('Persoana ',i,' introdu nume,adresa ,ocupatie, virsta:');
readln(s[i]);
readln(X[i]);
end; end;

procedure afis;
begin
writeln;
writeln('1-18 ani = ',j,' persoane');
writeln;
for i:=1 to j do 
writeln('nume:',s1[i],' virsta:',a[i],' ani'); 
writeln;
writeln('19-61 ani= ',k,' persoane');
writeln;
for i:=1 to k do 
writeln('nume:',s2[i],' virsta:',b[i],' ani'); 
writeln;
writeln('>61 ani   =',l,' persoane');
writeln;
for i:=1 to l do 
writeln('nume:',s3[i],' virsta:',c[i],' ani'); 
writeln;
end;

begin
writeln('nr persoane din localitate <5000:');
readln(n);
while exista do begin
include;
alegeelement;
end;
afis;
end.

Comentarii

Postări populare