function GetAList(Min, Max, Sum: Integer; Strs: TStrings): Integer;
var
I, J, K: Integer;
begin
Strs.Clear;
Result := 0;
if Max - Min < 2 then Exit; //区间内小于三个数,或者Max < Min
if Max * 3 - 3 <= Sum then Exit; //最大三个数之和小于Sum
Strs.BeginUpdate;
try
for I := Max downto Min - 2 do
for J := I - 1 downto Min - 1 do
for K := J - 1 downto Min do
if I + J + K > Sum then
Strs.Add(Format('%d+%d+%d', [I, J, K]));
finally
Strs.EndUpdate;
end;
Result := Strs.Count;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := '1到9之间任意三个数合大于12的组合共有' + IntToStr(GetAList(1, 9, 12, ListBox1.Items)) + '个';
end;