1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| Program Tournoi;
Uses CRT;
Const
nmax=100;
Type
tableau=array[1..nmax] of integer;
tableau2=array[1..nmax,1..nmax] of integer;
Var
A:tableau;
joueurs:tableau2;
i,j,k,dpge:integer;
{*** Procédure qui affiche le contenu d'un tableau ***}
Procedure ecriture(t:tableau;taille:integer);
var
i:integer;
begin
for i:=1 to taille do
write(t[i],' ');
writeln;
end;
{*** Procédure qui génère un tableau aléatoirement ***}
Procedure initialisation(var t:tableau;taille:integer);
var
i:integer;
begin
randomize;
for i:=1 to taille do
t[i]:=random(100);
ecriture(t,taille);
end;
Procedure Deux_PGE(t:tableau;taille:integer;var dpge:integer;var joueurs:tableau2);
Var
n,i,j,k,num_match,num_adv,ind_dpge,winner:integer;
adv:tableau;
matchs:tableau2;
Begin
n:=taille;
for i:=1 to n do
joueurs[1,i]:=i;
j:=2;
num_match:=1;
while (n <> 1) do
begin
k:=n div 2;
for i:=1 to k do
begin
if (t[joueurs[j-1,2*i-1]] > t[joueurs[j-1,2*i]]) then
joueurs[j,i]:=joueurs[j-1,2*i-1]
else
joueurs[j,i]:=joueurs[j-1,2*i];
matchs[num_match,1]:=joueurs[j-1,2*i-1];
matchs[num_match,2]:=joueurs[j-1,2*i];
num_match:=num_match+1;
end;
if (n mod 2 = 0) then
n:=k
else
begin
joueurs[j,k+1]:=joueurs[j-1,n];
n:=k;
end;
j:=j+1;
end;
num_match:=num_match-1;
winner:=joueurs[j,1];
{*** MARQUE 1 ***}
num_adv:=1;
for i:=1 to num_match do
begin
if (matchs[i,1] = winner) then
begin
adv[num_adv]:=matchs[i,2];
num_adv:=num_adv+1;
end
else
begin
if (matchs[i,2] = winner) then
begin
adv[num_adv]:=matchs[i,1];
num_adv:=num_adv+1;
end;
end;
end;
num_adv:=num_adv-1;
{*** MARQUE 2 ***}
ind_dpge:=adv[1];
for i:=2 to num_adv do
if (t[adv[i]] > t[ind_dpge]) then
ind_dpge:=adv[i];
dpge:=ind_dpge;
End;
Begin
clrscr;
initialisation(A,8);
j:=2;
Deux_PGE(A,8,dpge,joueurs);
for i:=1 to j-1 do
begin
for k:=1 to 8 do
write(joueurs[i,k],' ');
writeln;
end;
Writeln;
Writeln('DPGE : ',dpge);
readkey;
End. |
Partager