16,748
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.btn2Click(Sender: TObject);
var
iSelf: string;
i,iInt1, iMin, iMax, iResult: Integer;
procedure GetMinMax(vInt: string; out iMin, iMax: Integer);
var
temp: Char;
sMin, sMax: string;
i, j: Integer;
begin
sMin := vInt;
sMax := sMin;
for i := Length(vInt) - 1 downto 1 do
for j := 1 to i do
begin
if sMin[j] > sMin[j + 1] then
begin
temp := sMin[j];
sMin[j] := sMin[j + 1];
sMin[J + 1] := temp;
end;
if sMax[j] < sMax[j + 1] then
begin
temp := sMax[j];
sMax[j] := smax[j + 1];
sMax[j + 1] := temp;
end;
end;
iMin := StrToInt(sMin);
iMax := StrToInt(sMax);
end;
begin
Randomize;
i := 0;
while i < 3 do
begin
iSelf := iSelf + IntToStr(Random(9));
Inc(i);
end;
iSelf := IntToStr(StrToInt(iSelf)); //随机产生的三位数
GetMinMax(iSelf, iMin, iMax);
iResult := 0;
while StrToInt(iSelf) <> iResult do
begin
if StrToInt(iSelf) <> iResult then
iResult := StrToInt(iSelf);
GetMinMax(iSelf, iMin, imax);
iSelf := IntToStr(iMax - iMin);
end;
ShowMessage(iSelf);
end;