Write Delphi code that computes the median of an array of strings
- User
Write Delphi code that computes the median of an array of strings
Assistant
Here is an example of Delphi code that computes the median of an array of strings:
program MedianOfStrings;
{$APPTYPE CONSOLE}
uses SysUtils;
function Median(const A: array of string): string; var I, L, H: Integer; B: TStringList; begin B := TStringList.Create; try for I := Low(A) to High(A) do B.Add(A[I]); L := B.Count div 2; if B.Count mod 2 = 0 then begin Result := B[L - 1]; Result := Result + B[L]; Result := Result + '-'; end; if B.Count > 0 then Result := B[L - 1]; finally B.Free; end; end;
var Arr: array of string; Med: string; begin Arr := ['Apple', 'Banana', 'Cherry', 'Date', 'Eggplant']; Med := Median(Arr); Writeln(Med); Readln; end.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.