//求众数
function Most(var a: array of Integer): Integer;
//快速排序
procedure QuickSort(var a: array of Integer; iLo, iHi: Integer);
var
Lo, Hi, Mid, T: Integer;
begin
Lo:=iLo;
Hi:=iHi;
Mid:=a[(Lo+Hi)div 2];
repeat
while a[Lo]<Mid do
Inc(Lo);
while a[Hi]>Mid do
Dec(Hi);
if Lo<=Hi then begin
T:=a[Lo];
a[Lo]:=a[Hi];
a[Hi]:=T;
Inc(Lo);
Dec(Hi);
end;
until Lo>Hi;
if Hi>iLo then
QuickSort(a, iLo, Hi);
if Lo<iHi then
QuickSort(a, Lo, iHi);
end;
var
i, PreNum, PreCount, CurNum, CurCount: Integer;
begin
QuickSort(a, low(a), high(a));
PreNum:=-1;
PreCount:=-1;
CurNum:=-1;
CurCount:=-1;
for i:=low(a)to high(a) do begin
if CurNum=a[i] then begin
Inc(CurCount);
end
else begin
if CurCount>PreCount then begin
PreNum:=CurNum;
PreCount:=CurCount;
end;
CurNum:=a[i];
CurCount:=0;
Inc(CurCount);
end;
end;
if CurCount>PreCount then
Result:=CurNum
else
Result:=PreNum;
end;
//若有错误,请帮忙修改,谢谢!