Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program laba3;
- {$APPTYPE CONSOLE}
- uses
- SysUtils,
- Windows;
- Type
- TNodePtr = ^TNode;
- TNode = Record
- Index: Integer;
- Next: TNodePtr;
- end;
- var
- First: TNodePtr;
- N, k: Integer;
- procedure FillList(count: Integer; List: TNodePtr);
- var
- I: Integer;
- begin
- List^.Index := 1;
- for I := 2 to count do
- begin
- new(List^.Next);
- List := List^.Next;
- List^.Index := I;
- end;
- List^.Next := First;
- end;
- procedure PrintList(List: TNodePtr);
- var
- First: Integer;
- begin
- First := List.Index;
- while (First <> List.Next.Index) do
- begin
- Write(List^.Index:3);
- List := List^.Next;
- end;
- Write(List^.Index:3);
- end;
- procedure deleteEachKPrint(List: TNodePtr; k: Integer);
- var
- counter: Integer;
- begin
- counter := 1;
- while (List.Index <> List.Next.Index) do
- begin
- inc(counter);
- if (counter mod k = 0) then
- begin
- List^.Next := List^.Next^.Next;
- PrintList(List);
- writeln;
- end
- else
- List := List^.Next;
- end;
- end;
- procedure deleteEachK(List: TNodePtr; k: Integer);
- var
- counter: Integer;
- begin
- counter := 1;
- while (List.Index <> List.Next.Index) do
- begin
- inc(counter);
- if (counter mod k = 0) then
- List^.Next := List^.Next^.Next
- else
- List := List^.Next;
- end;
- writeln(List.Index);
- end;
- var
- I: Integer;
- begin
- new(First);
- writeln('введите количество человек n');
- Readln(N);
- FillList(N, First);
- writeln('Исходный список');
- PrintList(First);
- writeln;
- writeln('введите k');
- Readln(k);
- deleteEachKPrint(First, k);
- writeln('Решения для n от 1 до 64 при k = ',k);
- for I := 1 to 64 do
- begin
- new(First);
- FillList(I, First);
- write('При N = ', I, ' последний оставшийся ');
- deleteEachK(First, k)
- end;
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement