Cod sursa(job #1408845)

Utilizator casianos1996Marc Casian Nicolae casianos1996 Data 30 martie 2015 11:50:28
Problema Generare de permutari Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.77 kb
program gen_perm;
var s:array[1..10] of longint;
    n:longint;

procedure back(l:longint);
var       i,j:longint;
          ok:boolean;
begin
  if n=l then
    begin
      for i:=1 to l do
        write(s[i],' ');
      writeln;
    end
  else
    begin
      for i:=1 to n do
        begin
          ok:=true; j:=1;
          while(j<=l)and(ok) do
            begin
              if s[j]=i then ok:=false;
              inc(j);
            end;
          if ok then
            begin
              s[l+1]:=i;
              back(l+1);
            end;
          end;
        end;
end;

begin
  assign(input,'permutari.in'); reset(input);
  assign(output,'permutari.out'); rewrite(output);
  readln(n);
  back(0);
  close(input); close(output);
end.