function FindNum(aNum, aBegin, aEnd: Integer): Integer;function TForm1.FindNum(aNum, aBegin, aEnd: Integer): Integer;
var
liBegin, liEnd, liCenter: Integer;
begin
if (aNum<aBegin) or (aNum>aEnd) then
begin
Result:=0;
Exit;
end;
liBegin :=aBegin;
liEnd :=aEnd;
liCenter:=liBegin+Round( (liEnd-liBegin)/2 );
mList.Lines.Add( '第 '+FormatFloat('0000', temp+1)+' 次:'+FormatFloat('0000', liCenter)+
' 起:'+FormatFloat('0000', liBegin)+
' 止:'+FormatFloat('0000', liEnd) );
if aNum<liCenter then
begin
temp:=temp+1;
liEnd:=liCenter;
FindNum(aNum, liBegin, liEnd);
end
else if aNum>liCenter then
begin
temp:=temp+1;
liBegin:=liCenter;
FindNum(aNum, liBegin, liEnd);
end; Result:=temp+1;
end;FindNum(200, 0 , 1000);
var
liBegin, liEnd, liCenter: Integer;
begin
if (aNum<aBegin) or (aNum>aEnd) then
begin
Result:=0;
Exit;
end;
liBegin :=aBegin;
liEnd :=aEnd;
liCenter:=liBegin+Round( (liEnd-liBegin)/2 );
mList.Lines.Add( '第 '+FormatFloat('0000', temp+1)+' 次:'+FormatFloat('0000', liCenter)+
' 起:'+FormatFloat('0000', liBegin)+
' 止:'+FormatFloat('0000', liEnd) );
if aNum<liCenter then
begin
temp:=temp+1;
liEnd:=liCenter;
FindNum(aNum, liBegin, liEnd);
end
else if aNum>liCenter then
begin
temp:=temp+1;
liBegin:=liCenter;
FindNum(aNum, liBegin, liEnd);
end; Result:=temp+1;
end;FindNum(200, 0 , 1000);
liBegin:=liCenter;
FindNum(aNum, liBegin, liEnd);干什么?这样程序好看么?
if aNum<liCenter then
begin
temp:=temp+1;
FindNum(aNum, liBegin, liCenter);
end
else if aNum>liCenter then
begin
temp:=temp+1;
FindNum(aNum, liCenter, liEnd);
end; 呵呵 这样也好 不过我写成了统一格式: if aNum<liCenter then
begin
temp:=temp+1;
liEnd:=liCenter;
FindNum(aNum, liBegin, liEnd);
end
else if aNum>liCenter then
begin
temp:=temp+1;
liBegin:=liCenter;
FindNum(aNum, liBegin, liEnd);
end; 确实是为了好看 别见笑啊 人家是个完美主义者 不过以后会注意的 谢谢!
我讨厌有人问类似这样的问题:
s1='a';
s2='b';
如何实现s='a,b';