Advertisement
Darkrai1337

Untitled

Jan 24th, 2022
1,114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils,Math;
  7. type
  8.   TPerm = array of integer;
  9.  
  10. var
  11.   i,j,Range, Temp, First, Prev, Next : integer;
  12.   TopArr, InitArr, CycleArr: TPerm;
  13.   AllChainF: boolean = false;
  14. begin
  15.   Randomize;
  16.   Range := 6; //RandomRange(4, 10);
  17.   SetLength(TopArr, Range);
  18.   SetLength(InitArr, Range);
  19.  
  20.   for i:= 0 to high(TopArr) do
  21.   begin
  22.     TopArr[i] := i;
  23.     Write(' ',TopArr[i],' ');
  24.     InitArr[i] := i;
  25.   end;
  26.   Writeln;
  27.  
  28.   for i:= high(InitArr) downto 1 do
  29.   begin
  30.     j:= RandomRange(0, i+1);
  31.     temp:= InitArr[j];
  32.     InitArr[j] := InitArr[i];
  33.     InitArr[i] := temp;
  34.   end;
  35.   for i:= 0 to high(InitArr) do
  36.     write(' ',InitArr[i],' ');
  37.   Writeln;
  38.   Writeln;
  39.  
  40.   while AllChainF = false do
  41.   begin
  42.     AllChainF := true;
  43.     for i:= 0 to high(TopArr) do
  44.       if TopArr[i] <> -1 then
  45.       begin
  46.         AllChainF := false;
  47.         First := TopArr[i];
  48.         Write('( ',First,' ');
  49.         Next := InitArr[i];
  50.         TopArr[i] := -1;
  51.         break;
  52.       end;
  53.     while First <> Next do
  54.     begin
  55.       for j:= 0 to high(TopArr) do
  56.       begin
  57.         if Next = TopArr[j] then
  58.         begin
  59.           Write(' ',Next,' ');
  60.           Next := InitArr[j];
  61.           TopArr[j] := -1;
  62.         end;
  63.       end;
  64.     end;
  65.           if (First = Next) and (AllChainF = false) then
  66.          Write(')');
  67.  
  68.  
  69.   end;
  70.   Writeln;
  71.  
  72.       Readln;
  73.  
  74.  
  75. end.
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement