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
| program Exercice5;
// PAR EXEMPLE MARIE ET AIMER POUR LES ANAGRAMMES
function Anagramme(const s1:string;var s2:string):boolean;
var i,c:integer;
begin
i:=1;
result:=False;
if length(s1)=length(s2) then // Length(s1)=Length(s2)=5
begin
while (i<=length(s1)) and (length(s2)<>0) do //TANT QUE I<> Length(s1)+1 et que s2 n'est pas égal à chaîne de caractère vide alors on entre dans la boucle
begin
c:=pos(s1[i],s2);
inc(i);
writeln(result);
if (c<>0) then
begin
delete(s2,c,1); // ici on modifie la chaîne s2 donc on modifie le Result....
writeln(s2);
writeln(length(s2));
end;
end;// On sortira de la boucle quand i=6 et s2= ' '... Le Result devrait renvoyer TRUE...Je ne comprends pas mon erreur...
if length(s2)=0 then
result:=True
else
result:=False;
end;
end;
var ch1,ch2:string;
begin // PROGRAMME PRINCIPAL
writeln('Veuillez entrer 1 mots: ');
readln(ch1);
writeln('Veuillez entrer un 2e mot: ');
readln(ch2);
writeln(Anagramme(ch1,ch2));
end. |