Advertisement
Guest User

ForVlad

a guest
Jun 27th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.43 KB | None | 0 0
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6.  
  7. type
  8.    TStudent = record
  9.       Group: Integer;
  10.    end;
  11.    TStudentArr = array of TStudent;
  12.  
  13. const
  14.    N = 4;
  15.  
  16. function FindMaxGroup(var StudentArr: TStudentArr): Integer;
  17. var
  18.    i, j, CurrentGroup, CurrentCount, MaxGroup, MaxStudents, Temp: Integer;
  19. begin
  20.    for i := 0 to Length(StudentArr) - 1 do
  21.       for j := 0 to Length(StudentArr) - i do
  22.       begin
  23.          if StudentArr[j].Group < StudentArr[j + 1].Group then
  24.          begin
  25.             Temp := StudentArr[j].Group;
  26.             StudentArr[j].Group := StudentArr[j + 1].Group;
  27.             StudentArr[j + 1].Group := Temp;
  28.          end;
  29.       end;
  30.    i := 0;
  31.    MaxStudents := 0;
  32.    while i < N do
  33.    begin
  34.       CurrentGroup := StudentArr[i].Group;
  35.       CurrentCount := 1;
  36.       Inc(i);
  37.       while (i < N) and (StudentArr[i].Group = Currentgroup) do
  38.       begin
  39.          Inc(CurrentCount);
  40.          Inc(I);
  41.       end;
  42.       if CurrentCount > MaxStudents then
  43.       begin
  44.          MaxGroup := CurrentGroup;
  45.          MaxStudents := CurrentCount;
  46.       end;
  47.    end;
  48.    Result := MaxGroup;
  49. end;
  50.  
  51. var
  52.    F: TextFile;
  53.    StudentArr: TStudentArr;
  54.    i, Group: Integer;
  55.  
  56. begin
  57.    SetLength(StudentArr, 4);
  58.    AssignFile(F, 'input.txt');
  59.    Reset(F);
  60.    for i := 0 to 3 do
  61.    begin
  62.       Read(F, StudentArr[i].Group);
  63.    end;
  64.    Group := FindMaxGroup(StudentArr);
  65.    Writeln(Group);
  66.    Readln;
  67. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement