Cod sursa(job #750393)

Utilizator andrei_toaderToader Andrei Sorin andrei_toader Data 21 mai 2012 23:55:13
Problema Generare de permutari Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.68 kb
var f,g:text;
    n:byte;
    x:array[1..8] of byte;

function cont (k:byte):boolean;
var i:byte;

begin
 cont:=true;
 for i:=1 to k-1 do
  if x[i]=x[k] then
  begin
   cont:=false; break;
  end;
end;

procedure bkt;
var k,i:byte;
begin
 k:=1; x[k]:=0;
 while k>0 do
   if x[k]<n then
   begin
    inc(x[k]);
    if cont(k) then
     if k=n then
     begin
      for i:=1 to n do
       write (g,x[i],' ');
      writelN (G);
     end
     else
     begin
      inc(k); x[k]:=0;
     end;
   end
   else
    k:=k-1;
end;

begin
 assign (f,'permutari.in'); reset (f);
 assign (g,'permutari.out'); rewrite (g);
 read (f,n);
 bkt;
 close (f); close (g);
end.