没人回复额,把我写的垃圾代码贴上来吧! 用了很多次强制转换蛮慢。
function Taxis(int: integer; MaxToMin: Boolean): Integer;
var
i , j : Integer;
s , x : String;
begin
s := IntToStr(int);
if MaxToMin then
begin
for i := 1 to Length(s) do
begin
for j := i +1 to Length(s) do
begin
if StrToInt(s[j]) > StrToInt(s[i])then
begin
x := s[i];
s[i] := s[j];
s[j] := x[1];
end;
end;
end;
end
else
begin
for i := 1 to Length(s) do
begin
for j := i +1 to Length(s) do
begin
if StrToInt(s[j]) < StrToInt(s[i])then
begin
x := s[j];
s[j] := s[i];
s[i] := x[1];
end;
end;
end;
end;
Result := StrToInt(s);
end;
|