Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TIAMode(TIA: TIntegerArray): Integer;
- var
- mn, mx, x, y, t: Integer;
- b: TIntegerArray;
- begin
- y := High(TIA);
- if (y > -1) then
- begin
- mn := TIA[0];
- mx := TIA[0];
- if (y > 0) then
- for x := 1 to y do
- if (TIA[x] < mn) then
- mn := TIA[x]
- else
- if (TIA[x] > mx) then
- mx := TIA[x];
- {$IFNDEF Lape}
- SetLength(b, (IAbs(mn - mx) + 1));
- {$ELSE}
- SetLength(b, (Abs(mn - mx) + 1));
- {$ENDIF}
- for x := 0 to (mx - mn) do
- b[x] := 0;
- for x := 0 to y do
- Inc(b[(TIA[x] - mn)]);
- t := 0;
- if ((mx - mn) > 0) then
- for x := 0 to (mx - mn) do
- if (b[x] > b[t]) then
- t := x;
- Result := (t + mn);
- SetLength(b, 0);
- end else
- Result := -1;
- end;
- var
- TIA: TIntegerArray;
- begin
- TIA := [-5, -1, 3, -1, 3, 3, 5, 5, 3, 3, 5, 5, 5, 5, 5, 5, -1, 1, -1, -6, 2, 3, -1, -9, 3, -1, 4, -1, 5, 3, 3, 3, -1, 5, -1];
- WriteLn(TIAMode(TIA));
- end.
Advertisement
Add Comment
Please, Sign In to add comment