你可以使用穷举的方法,写6个循环从1至35,把值相加看是不是105。
procedure TForm1.Button1Click(Sender: TObject);
const m = 35;
var
count, k, v, i1, i2, i3, i4, i5, i6: integer;
s, ss : string;
begin
k := 105;
count := 0;
ss := '';
for i1 := 1 to m do
begin
for i2 := i1+1 to m do
begin
if i1 = i2 then continue;
for i3 := i2+1 to m do
begin
if (i3=i1) or (i3=i2) then continue;
for i4 := i3+1 to m do
begin
if (i4=i1) or (i4=i2) or (i4=i3) then continue;
for i5 := i4+1 to m do
begin
if (i5=i1) or (i5=i2) or (i5=i3) or (i5=i4) then continue;
for i6 := i5+1 to m do
begin
if (i6=i1) or (i6=i2) or (i6=i3) or (i6=i4) or (i6=i5) then continue;
if i1 + i2 + i3 + i4 + i5 + i6 = k then
begin
inc(count);
// s := format('%d, %d, %d, %d, %d, %d', [i1, i2, i3, i4, i5, i6]);
// ss := ss+#13#10+s;
end;
end;
end;
end;
end;
end;
end;
memo1.lines.add(inttostr(count)+ '个');
//savestring(ss, 'h:\result.txt');
end;
|