Cod sursa(job #1507195)

Utilizator ili226Vlad Ilie ili226 Data 21 octombrie 2015 15:40:56
Problema Generare de permutari Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.58 kb
var k,i,j,n:byte;
    p:array[1..8]of byte;
    f,fo:text;
    bun:boolean;
begin
assign(f,'permutari.in');
assign(fo,'permutari.out');
reset(f);
rewrite(fo);
readln(f,n);
close(f);
i:=1;p[i]:=0;
repeat
 while p[i]<n do
  begin
   inc(p[i]);
   bun:=true;
   for k:=1 to i-1 do
    if p[k]=p[i] then bun:=false;
   if bun then
    if i<=n then
     if i=n then
      begin
       for k:=1 to n do write(fo,p[k],' ');
       writeln(fo)
      end
            else
      begin
       inc(i);
       p[i]:=0;
      end;
  end;
dec(i);
until i=0;
close(fo);
end.