Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Задачи на Pascal/Object Pascal/Free Pascal (Delphi/Lazarus)

Модерирует : ShIvADeSt

 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

Открыть новую тему     Написать ответ в эту тему

derelict



Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору

Код:
 
(*===================================================================*)
(* Pascal program for distribution from the Combinatorial Object   *)
(* Server. Generate permutations in lexicographic order. This is   *)
(* the same version used in the book "Combinatorial Generation."   *)
(* The program can be modified, translated to other languages, etc., *)
(* so long as proper acknowledgement is given (author and source).   *)
(* Programmer: Joe Sawada, 1997.                   *)
(* The latest version of this program may be found at the site     *)
(* http://theory.cs.uvic.ca/inf/perm/PermInfo.html          *)
(*===================================================================*)
 
program Permlex (input, output);
 
var
    n : integer;
    i : integer;
    a : array [0..100] of integer;   { The permutation }
 
procedure PrintPerm;
var j:integer;
begin
 
    for j:=1 to n do write(a[j]:1);
    writeln;
end;
 
procedure swap(i:integer; j:integer);
var temp : integer;
begin
 
    temp := a[i];
    a[i] := a[j];
    a[j] := temp;
end;
 
function Next : integer;
var k,j,r,s : integer;
begin
 
    k := n-1;
    while a[k] > a[k+1] do k:=k-1;
    if k = 0 then Next:=0
    else begin
        j := n;
        while a[k] > a[j] do j:=j-1;
        swap(j,k);
        r:=n;
        s:=k+1;
        while r>s do begin
            swap(r,s);
            r:=r-1;
            s:=s+1;
        end;
        Next:=1;
        PrintPerm();
     end;
end;
 
begin
 
    write('Enter n: '); readln(n);
    writeln;
    if n > 0 then begin
        for  i := 0 to n do a[i] := i;
        PrintPerm;
        while (Next = 1) do ;
        writeln;
    end;
  readln;
end.
 

Всего записей: 232 | Зарегистр. 11-06-2006 | Отправлено: 18:42 21-12-2009
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Задачи на Pascal/Object Pascal/Free Pascal (Delphi/Lazarus)


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru