Advertisement
gguuppyy

АИСД, 1.2

Mar 14th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. program lab1;
  2.  
  3. uses
  4. System.SysUtils,
  5. windows;
  6.  
  7. Const
  8. MIN_AMOUNT_OF_PEOPLE = 1;
  9. MAX_AMOUNT_OF_PEOPLE = 64;
  10. MIN_RETIRED_NUMBER = 1;
  11. MAX_RETIRED_NUMBER = 64;
  12.  
  13. Type
  14. Pt = ^Person;
  15. Person = Record
  16. Number: Byte;
  17. Next: Pt;
  18. End;
  19.  
  20. Function ReadRetiredNumber() : Integer;
  21. Var
  22. RetiredNumber: Integer;
  23. IsCorrect: Boolean;
  24. Begin
  25. WriteLn('Введите число K в интервале [', MIN_RETIRED_NUMBER, '; ', MAX_RETIRED_NUMBER, ']: ');
  26. RetiredNumber := 0;
  27. Repeat
  28. IsCorrect := True;
  29. Try
  30. ReadLn(RetiredNumber);
  31. Except
  32. IsCorrect := False;
  33. End;
  34. IsCorrect := IsCorrect And (RetiredNumber >= MIN_RETIRED_NUMBER) And (RetiredNumber <= MAX_RETIRED_NUMBER);
  35. If Not IsCorrect Then
  36. WriteLn('Пожалуйста, введите корректное значение: ');
  37. Until IsCorrect;
  38. ReadRetiredNumber := RetiredNumber;
  39. End;
  40.  
  41.  
  42.  
  43. Procedure MakeListOfPeople(AmountOfPeople: Integer; Var ListOfPeople: Pt);
  44. Var
  45. FirstPerson: Pt;
  46. I: Integer;
  47. Begin
  48. New(ListOfPeople);
  49. ListOfPeople^.Number := 1;
  50. FirstPerson := ListOfPeople;
  51. For I := 2 To AmountOfPeople Do
  52. Begin
  53. New(ListOfPeople^.Next);
  54. ListOfPeople := ListOfPeople^.Next;
  55. ListOfPeople^.Number := I;
  56. End;
  57. ListOfPeople^.Next := FirstPerson;
  58. End;
  59.  
  60. Procedure PlayRound(RetiredNumber: Integer; ListOfPeople: Pt);
  61. Var
  62. Counter: Integer;
  63. Begin
  64. Counter := 1;
  65. While ListOfPeople^.Next <> ListOfPeople Do
  66. Begin
  67. If Counter = RetiredNumber Then
  68. Begin
  69. Write(ListOfPeople^.Next^.Number, ' ');
  70. ListOfPeople^.Next := ListOfPeople^.Next^.Next;
  71. Counter := 0;
  72. End
  73. Else
  74. ListOfPeople := ListOfPeople^.Next;
  75. Inc(Counter);
  76. End;
  77. Write(' | ', ListOfPeople^.Number);
  78. End;
  79.  
  80. Procedure PlayGame(RetiredNumber: Integer);
  81. Var
  82. ListOfPeople: Pt;
  83. AmountOfPeople: Integer;
  84. Begin
  85. WriteLn;
  86. For AmountOfPeople := MIN_AMOUNT_OF_PEOPLE To MAX_AMOUNT_OF_PEOPLE Do
  87. Begin
  88. Write('N = ', Format('%-3s|', [IntToStr(AmountOfPeople)]));
  89. New(ListOfPeople);
  90. MakeListOfPeople(AmountOfPeople, ListOfPeople);
  91. PlayRound(RetiredNumber, ListOfPeople);
  92. WriteLn;
  93. End;
  94. End;
  95.  
  96.  
  97.  
  98. Var
  99. RetiredNumber: Integer;
  100. Begin
  101. SetConsoleCP(1251);
  102. SetConsoleOutputCP(1251);
  103. RetiredNumber := ReadRetiredNumber();
  104. PlayGame(RetiredNumber);
  105.  
  106. WriteLn;
  107. Write('Нажмите Enter для завершения программы...');
  108. ReadLn;
  109. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement