Generare password casuali Funzione redirect
Aug 20

Algoritmo permutazioni con ripetizione

program prova2;
uses crt;
var s         : string;
    stack     : string;
    stack_idx : longint;
    risposta :string;
function estratto(t : string; i : integer) : string;
begin
  delete(t, i, 1);
  estratto := t;
end;
 
procedure scrivi_perm(t : string);
var i : integer;
begin
  if length(t) = 0 then
  begin
    inc(stack_idx);
    writeln(stack_idx:5, ') ' + stack);
  end
  else
    for i := 1 to length(t) do
    begin
      stack := stack + t[i];
      scrivi_perm(estratto(t, i));
      stack := copy(stack, 1, length(stack)-1);
    end;
end;
 
begin
repeat
clrscr;
  stack := '';
  stack_idx := 0;
  write('parola : '); readln(s);
  scrivi_perm(s);
  readln;
  writeln('Vuoi Continuare?');
  readln(risposta);
  until (risposta<>'s');
end.

(Nessun voto)
Loading ... Loading ...

Inserisci il tuo Commento:

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a