注:TBuffer类见 http://www.delphibbs.com/delphibbs/dispq.asp?lid=968511
function PNMNum(N,M:Integer)
ouble;
var
i:Integer;
begin
Result:=1;
for i:=N-M+1 to Ndo
Result:=Result*i;
end;
function PNM(const N,M:Integer;out Count:Integer):String;
var
A:array of Integer;
i:Integer;
Buf:TBuffer;
StartTime
Word;
TotalCount
ouble;
procedure Gen(Level:Integer);
var
j,mm:Integer;
mstr:String;
begin
if Level=M then
begin
mstr:='';
for j:=0 to M-1do
mstr:=mstr+IntToStr(A[j])+#9;
mstr:=mstr+#13#10;
Buf.WriteBuf(@mstr[1],Length(mstr));
Inc(Count);
if Count mod 1000=0 then
begin
Form1.Caption:=Format('%.3f%% %.7d Time: %.2fs Buffer Size: %.2fM',
[100*Count/TotalCount,Count,(GetTickCount-StartTime)/1000,
Buf.ContentSize/(1024*1024)]);
Application.ProcessMessages;
end;
exit;
end;
mm:=A[Level];
for j:=Level to N-1do
begin
A[Level]:=A[j];
A[j]:=mm;
Gen(Level+1);
A[j]:=A[Level];
A[Level]:=mm;
end;
end;
begin
Result:='';
Count:=0;
if (N<1) or (M>N) or (M<1) then
exit;
Buf:=TBuffer.Create(0,4*1024*1024);
SetLength(A,N);
TotalCount:=PNMNum(N,M);
StartTime:=GetTickCount;
for i:=0 to N-1do
A
:=i;
Gen(0);
Result:=Buf.AsString;
Buf.Free;
end;
>>write(cc[j],' ');
执行时出错
那是DOS输出,你新建一个Console App就可以用了。