Advertisement
Janilabo

Untitled

Dec 28th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.00 KB | None | 0 0
  1. function GetMode(TEA: TExtendedArray): Extended;
  2. var
  3.   h, i, f, m: Integer;
  4. begin
  5.   h := High(TEA);
  6.   case (h > -1) of
  7.     True:
  8.     case (h = 0) of
  9.       False:
  10.       begin
  11.         Result := TEA[0];
  12.         f := 1;
  13.         m := 0;
  14.         for I := 1 to High (TEA) do
  15.         case (TEA[(I - 1)] = TEA[I]) of
  16.           False:
  17.           if (f <> 1) then
  18.           begin
  19.             if (f > m) then
  20.             begin
  21.               Result := TEA[(I - 1)];
  22.               m := f;
  23.             end;
  24.             f := 1;
  25.           end;
  26.           True: Inc(f);
  27.         end;
  28.         case (m > 0) of
  29.           True:
  30.           if (f > m) then
  31.             Result := TEA[h];
  32.           False:
  33.           if (f > 1) then
  34.             Result := TEA[h];  
  35.         end;
  36.       end;
  37.       True: Result := TEA[0];
  38.     end;
  39.     False: Result := -1;
  40.   end;
  41. end;
  42.  
  43. var
  44.   TEA: TExtendedArray;
  45.  
  46. begin
  47.   TEA := [0.3, 0.3, 0.3, 0.3, 0.4, 0.4, 0.5, 0.5, 0.5, 0.6, 0.8, 0.8, 0.8, 0.8];
  48.   WriteLn(GetMode(TEA));
  49. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement