procedure TForm1.Button1Click(Sender: TObject); var i,j,k:integer; str:string; begin for i:= 1 to 100 do for j:= 1 to 33 do begin k:= 100-i-j; if (i*1 + j*3 + k/3)=100 then begin str:= '公鸡'+ inttostr(i) +'只; ' + '母鸡'+ inttostr(j) +'只; '+ '小鸡'+ inttostr(k) +'只'; Memo1.Lines.Add(str); end; end;end;====================== 公鸡4只; 母鸡24只; 小鸡72只 公鸡8只; 母鸡23只; 小鸡69只 公鸡12只; 母鸡22只; 小鸡66只 公鸡16只; 母鸡21只; 小鸡63只 公鸡20只; 母鸡20只; 小鸡60只 公鸡24只; 母鸡19只; 小鸡57只 公鸡28只; 母鸡18只; 小鸡54只 公鸡32只; 母鸡17只; 小鸡51只 公鸡36只; 母鸡16只; 小鸡48只 公鸡40只; 母鸡15只; 小鸡45只 公鸡44只; 母鸡14只; 小鸡42只 公鸡48只; 母鸡13只; 小鸡39只 公鸡52只; 母鸡12只; 小鸡36只 公鸡56只; 母鸡11只; 小鸡33只 公鸡60只; 母鸡10只; 小鸡30只 公鸡64只; 母鸡9只; 小鸡27只 公鸡68只; 母鸡8只; 小鸡24只 公鸡72只; 母鸡7只; 小鸡21只 公鸡76只; 母鸡6只; 小鸡18只 公鸡80只; 母鸡5只; 小鸡15只 公鸡84只; 母鸡4只; 小鸡12只 公鸡88只; 母鸡3只; 小鸡9只 公鸡92只; 母鸡2只; 小鸡6只 公鸡96只; 母鸡1只; 小鸡3只
2.使用API函数FindFirstFile, FindNextFile, FindClose用递归算法列出你计算机D:\目录下的所有目录及文件. //******************************** form 上一个按钮:btn1,一个TStringGrid :StringGrid1procedure TForm1.btn1Click(Sender: TObject); var sr: TSearchRec; FileAttrs: Integer; procedure FindFile(const p: string;A: Integer; var F: TSearchRec;line: Integer; grid:TStringGrid); var d,Tempstr:string; i,Lline: Integer; FF: TSearchRec; begin Tempstr:=''; i:=0; while Tempstr<>'\' do begin Tempstr:=Copy(p,Length(P)-i,1); Inc(i); end; d:=Copy(p,1,Length(P)-i); if FindFirst(p, A, F) = 0 then begin repeat if ((F.Attr and A) = F.Attr) and (F.Name <>'.') and (F.Name <>'..') then begin grid.ColCount := grid.ColCount + line; grid.RowCount := grid.RowCount + 1; Lline := line+1; grid.Cells[Lline,grid.RowCount-1] := F.Name; if F.Attr=faDirectory then begin grid.Cells[Lline+1,grid.RowCount-1] :='目录'; FF:=F; FindFile(d+'\'+FF.Name+'\*.*',A,FF,Lline,Grid); end else grid.Cells[Lline+1,grid.RowCount-1] := IntToStr(F.Size); end; until FindNext(F) <> 0; FindClose(F); end; end; begin StringGrid1.RowCount := 1; FileAttrs := faReadOnly+ faHidden+ faSysFile+ faVolumeID+ faDirectory+ faArchive+ faAnyFile; StringGrid1.RowCount := 0; FindFile('D:\*.*',FileAttrs,sr,0,StringGrid1); end;
楼上用的是API函数FindFirstFile, FindNextFile吗?楼主要自己改一下哈~
begin for i:= 0 to 100 do for j:= 0 to (100-i) div 3 do begin k:= (100-i-j*3)*3; if (i+ j+ k)=100 then begin str:= '公鸡'+ inttostr(i) +'只; ' + '母鸡'+ inttostr(j) +'只; '+ '小鸡'+ inttostr(k) +'只'; Memo1.Lines.Add(str); end; end;end;
var i,j,k:integer;
str:string;
begin
for i:= 1 to 100 do
for j:= 1 to 33 do
begin
k:= 100-i-j;
if (i*1 + j*3 + k/3)=100 then
begin
str:= '公鸡'+ inttostr(i) +'只; ' +
'母鸡'+ inttostr(j) +'只; '+
'小鸡'+ inttostr(k) +'只'; Memo1.Lines.Add(str);
end;
end;end;======================
公鸡4只; 母鸡24只; 小鸡72只
公鸡8只; 母鸡23只; 小鸡69只
公鸡12只; 母鸡22只; 小鸡66只
公鸡16只; 母鸡21只; 小鸡63只
公鸡20只; 母鸡20只; 小鸡60只
公鸡24只; 母鸡19只; 小鸡57只
公鸡28只; 母鸡18只; 小鸡54只
公鸡32只; 母鸡17只; 小鸡51只
公鸡36只; 母鸡16只; 小鸡48只
公鸡40只; 母鸡15只; 小鸡45只
公鸡44只; 母鸡14只; 小鸡42只
公鸡48只; 母鸡13只; 小鸡39只
公鸡52只; 母鸡12只; 小鸡36只
公鸡56只; 母鸡11只; 小鸡33只
公鸡60只; 母鸡10只; 小鸡30只
公鸡64只; 母鸡9只; 小鸡27只
公鸡68只; 母鸡8只; 小鸡24只
公鸡72只; 母鸡7只; 小鸡21只
公鸡76只; 母鸡6只; 小鸡18只
公鸡80只; 母鸡5只; 小鸡15只
公鸡84只; 母鸡4只; 小鸡12只
公鸡88只; 母鸡3只; 小鸡9只
公鸡92只; 母鸡2只; 小鸡6只
公鸡96只; 母鸡1只; 小鸡3只
//********************************
form 上一个按钮:btn1,一个TStringGrid :StringGrid1procedure TForm1.btn1Click(Sender: TObject);
var
sr: TSearchRec;
FileAttrs: Integer;
procedure FindFile(const p: string;A: Integer; var F: TSearchRec;line: Integer; grid:TStringGrid);
var
d,Tempstr:string;
i,Lline: Integer;
FF: TSearchRec;
begin
Tempstr:='';
i:=0;
while Tempstr<>'\' do
begin
Tempstr:=Copy(p,Length(P)-i,1);
Inc(i);
end;
d:=Copy(p,1,Length(P)-i);
if FindFirst(p, A, F) = 0 then
begin
repeat
if ((F.Attr and A) = F.Attr) and (F.Name <>'.') and (F.Name <>'..') then
begin
grid.ColCount := grid.ColCount + line;
grid.RowCount := grid.RowCount + 1;
Lline := line+1;
grid.Cells[Lline,grid.RowCount-1] := F.Name;
if F.Attr=faDirectory then
begin
grid.Cells[Lline+1,grid.RowCount-1] :='目录';
FF:=F;
FindFile(d+'\'+FF.Name+'\*.*',A,FF,Lline,Grid);
end
else
grid.Cells[Lline+1,grid.RowCount-1] := IntToStr(F.Size);
end;
until FindNext(F) <> 0;
FindClose(F);
end;
end;
begin
StringGrid1.RowCount := 1;
FileAttrs := faReadOnly+ faHidden+ faSysFile+ faVolumeID+ faDirectory+ faArchive+ faAnyFile;
StringGrid1.RowCount := 0;
FindFile('D:\*.*',FileAttrs,sr,0,StringGrid1);
end;
for i:= 0 to 100 do
for j:= 0 to (100-i) div 3 do
begin
k:= (100-i-j*3)*3;
if (i+ j+ k)=100 then
begin
str:= '公鸡'+ inttostr(i) +'只; ' +
'母鸡'+ inttostr(j) +'只; '+
'小鸡'+ inttostr(k) +'只'; Memo1.Lines.Add(str);
end;
end;end;