Pagini recente » Cod sursa (job #1242503) | Cod sursa (job #244858) | Cod sursa (job #1921372) | Cod sursa (job #304020) | Cod sursa (job #383592)
Cod sursa(job #383592)
var
fi, fo : text;
a : array [0..8] of byte;
i, j, aux, n : byte;
continuam : boolean;
begin
assign (fi, 'permutari.in'); reset (fi);
assign (fo, 'permutari.out'); rewrite (fo);
read (fi, n);
for i := 1 to n do
begin
a[i] := i;
write (fo, i, ' ');
end;
writeln (fo);
repeat
i := n-1;
while a[i] > a[i+1] do
dec (i);
continuam := i >= 1;
if continuam then
begin
j := n;
while a[i] > a[j] do
dec (j);
aux := a[i]; a[i] := a[j]; a[j] := aux;
inc (i); j := n;
repeat
aux := a[i]; a[i] := a[j]; a[j] := aux; inc (i); dec (j);
until i >= j;
for i := 1 to n do
write (fo, a[i], ' ');
writeln (fo)
end;
until not continuam;
close (fi); close (fo);
end.
53287641
i j
53487621
87621
i j
53412678