我来贴一个笨一点的方法给你看一下!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
ta=array[1..10] of integer;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
function istrue(a:ta):boolean;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var a:ta;
i,j,s,k:integer;
begin
for i:=102 to 987 do
begin
a[1]:=i div 100;
//beep;
a[2]:=(i-a[1]*100) div 10;
a[3]:=i mod 10;
for j:=4 to 10 do
a[j]:=j-20;
if istrue(a) then
Continue;
for j:=102 to 987 do
begin
a[4]:=j div 100;
a[5]:=(j-a[4]*100) div 10;
a[6]:=j mod 10;
if istrue(a) then
continue
else
begin
s:=i+j;
//beep;
a[7]:=s div 1000;
a[8]:=s div 100 mod 10;
a[9]:=s div 10 mod 10;
a[10]:=s mod 10;
if istrue(a) then
begin
for k:=7 to 10 do
a[k]:=k-20;
continue;
end
else
listbox1.Items.Add(inttostr(i)+'+'+inttostr(j)+'='+inttostr(s));
end;
end;
end;
end;
function TForm1.istrue(a: ta): boolean;
var
i,j:integer;
begin
result:=False;
for i:=1 to 9 do
begin
for j:=i+1 to 10 do
if a=a[j] then
begin
result:=true;
exit;
end;
end;
end;
end.