Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project1;
- {$APPTYPE CONSOLE}
- {$R *.res}
- type
- TStudent = record
- Group: Integer;
- end;
- TStudentArr = array of TStudent;
- const
- N = 4;
- function FindMaxGroup(var StudentArr: TStudentArr): Integer;
- var
- i, j, CurrentGroup, CurrentCount, MaxGroup, MaxStudents, Temp: Integer;
- begin
- for i := 0 to Length(StudentArr) - 1 do
- for j := 0 to Length(StudentArr) - i do
- begin
- if StudentArr[j].Group < StudentArr[j + 1].Group then
- begin
- Temp := StudentArr[j].Group;
- StudentArr[j].Group := StudentArr[j + 1].Group;
- StudentArr[j + 1].Group := Temp;
- end;
- end;
- i := 0;
- MaxStudents := 0;
- while i < N do
- begin
- CurrentGroup := StudentArr[i].Group;
- CurrentCount := 1;
- Inc(i);
- while (i < N) and (StudentArr[i].Group = Currentgroup) do
- begin
- Inc(CurrentCount);
- Inc(I);
- end;
- if CurrentCount > MaxStudents then
- begin
- MaxGroup := CurrentGroup;
- MaxStudents := CurrentCount;
- end;
- end;
- Result := MaxGroup;
- end;
- var
- F: TextFile;
- StudentArr: TStudentArr;
- i, Group: Integer;
- begin
- SetLength(StudentArr, 4);
- AssignFile(F, 'input.txt');
- Reset(F);
- for i := 0 to 3 do
- begin
- Read(F, StudentArr[i].Group);
- end;
- Group := FindMaxGroup(StudentArr);
- Writeln(Group);
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement