Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program task3;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- type
- TParticipant = class
- Surname: String;
- Points: Integer;
- constructor Create(Surname: String; Points: Integer);
- end;
- type
- ParticipantsArr = array of TParticipant;
- constructor TParticipant.Create(Surname: String; Points: Integer);
- begin
- Self.Surname := Surname;
- Self.Points := Points;
- end;
- function CheckInput(): Integer;
- var
- Value: Integer;
- begin
- try
- Readln(Value);
- except
- Value := -1;
- end;
- CheckInput := Value;
- end;
- procedure Sort(var Participants: ParticipantsArr);
- var
- i, j, MaxIdx, Points, MaxPoints: Integer;
- Surname, MaxSurname: String;
- Res: Byte;
- Participant: TParticipant;
- begin
- for i := 0 to High(Participants) do
- begin
- Participant := Participants[i];
- MaxIdx := i;
- for j := i + 1 to High(Participants) do
- begin
- Points := Participants[j].Points;
- MaxPoints := Participants[MaxIdx].Points;
- if(Points = MaxPoints) then
- begin
- Surname := AnsiLowerCase(Participants[j].Surname);
- MaxSurname := AnsiLowerCase(Participants[MaxIdx].Surname);
- if (Surname < MaxSurname) then
- MaxIdx := j;
- end
- else if (Points > MaxPoints) then
- MaxIdx := j;
- end;
- if(MaxIdx <> i) then
- begin
- Participants[i] := Participants[MaxIdx];
- Participants[MaxIdx] := Participant;
- end;
- end;
- end;
- procedure ShowResult(const Participants: ParticipantsArr);
- var
- i: Integer;
- begin
- for i := 0 to High(Participants) do
- Writeln(Participants[i].Surname, ' ', Participants[i].Points);
- end;
- function InputParticipants(): ParticipantsArr;
- var
- Participants: ParticipantsArr;
- ParticipantsCount, Points, i: Integer;
- Surname: String;
- NotCorrect: Boolean;
- begin
- NotCorrect := true;
- while(NotCorrect) do
- begin
- Writeln('Введите количество участников');
- ParticipantsCount := CheckInput();
- if(ParticipantsCount > 0) then
- NotCorrect := false
- else
- Writeln('Количество участников должно быть натуральным числом');
- end;
- SetLength(Participants, ParticipantsCount);
- i := 0;
- while(i < ParticipantsCount) do
- begin
- Writeln('Введите фамилию участника');
- Readln(Surname);
- Writeln('Введите количество баллов');
- Points := CheckInput();
- if(Points > 0) then
- begin
- Participants[i] := TParticipant.Create(Surname, Points);
- Inc(i);
- end
- else
- Writeln('Количество баллов участника должно быть натуральным числом. Повторите ввод');
- end;
- InputParticipants := Participants;
- end;
- procedure Main();
- var
- Participants: ParticipantsArr;
- begin
- Writeln('Данная программа сортирует участников соревнования по убыванию количества баллов', #13#10);
- Participants := InputParticipants();
- Sort(Participants);
- Writeln('Результат:');
- ShowResult(Participants);
- end;
- begin
- Main();
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement