Janilabo

TIAMode()

Aug 2nd, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.97 KB | None | 0 0
  1. function TIAMode(TIA: TIntegerArray): Integer;
  2. var
  3.   mn, mx, x, y, t: Integer;
  4.   b: TIntegerArray;
  5. begin
  6.   y := High(TIA);
  7.   if (y > -1) then
  8.   begin
  9.     mn := TIA[0];
  10.     mx := TIA[0];
  11.     if (y > 0) then
  12.     for x := 1 to y do
  13.       if (TIA[x] < mn) then
  14.         mn := TIA[x]
  15.       else
  16.         if (TIA[x] > mx) then
  17.           mx := TIA[x];
  18.     {$IFNDEF Lape}
  19.       SetLength(b, (IAbs(mn - mx) + 1));
  20.     {$ELSE}
  21.       SetLength(b, (Abs(mn - mx) + 1));
  22.     {$ENDIF}
  23.     for x := 0 to (mx - mn) do
  24.       b[x] := 0;
  25.     for x := 0 to y do
  26.       Inc(b[(TIA[x] - mn)]);
  27.     t := 0;
  28.     if ((mx - mn) > 0) then
  29.     for x := 0 to (mx - mn) do
  30.       if (b[x] > b[t]) then
  31.         t := x;
  32.     Result := (t + mn);
  33.     SetLength(b, 0);
  34.   end else
  35.     Result := -1;
  36. end;
  37.  
  38. var
  39.   TIA: TIntegerArray;
  40.  
  41. begin
  42.   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];
  43.   WriteLn(TIAMode(TIA));
  44. end.
Advertisement
Add Comment
Please, Sign In to add comment