//你看看这个函数可不可以..没优化尼..有啥毛病你改一改吧.. function TForm1.OrderNum(StrNum: string): string; var i:integer; j:integer; LenStr:integer; StrTemp:Char; IntTempA:integer; IntTempB:integer; begin LenStr:=Length(StrNum); for i:=1 to Lenstr do begin for j:=I+1 to LenStr do begin IntTempA:=StrToInt(StrNum[i]); IntTempB:=StrToInt(StrNum[j]); if IntTempA>IntTempB then begin StrTemp:=StrNum[i]; StrNum[i]:=StrNum[j]; StrNum[j]:=StrTemp; end; end; end; result:=StrNum; end;
Program sort(input,output); var a:Array[1..20] OF real; temp:real; i,j:integer; flag:boolean; Begin for i:=1 to 20 do read(a[i]); i:=1; Repeat flag:=true; For j:=j to 20-i do IF a[j]<a[j+1] Then Begin temp:=a[j]; a[j]:=a[j+1]; a[j+1]:=temp; flag:=false; End ; i:=i+1; Until flag; For i:=1 to 20 do write(a[j]) END.
var sL: TStringList; s: string; I: integer; begin s := '2142333'; sL := TStringList.Create; for I:=1 to Length(s) do sL.Add(s[i]); sL.Sort; s := sL.Text; s := StringReplace(s, #13#10, '', [rfReplaceAll]); FreeAndNil(sL); showMessage(s); end;
pChr:=strPCopy(pChr,'2142333'); L:=0;R:=length('2142333');procedure QuickSort(pChr:Pchar;L, R: Integer); var I, J, P: Integer; function cmpChr(a,b:char):integer; var strInfo:string ; iA,iB:integer; id:integer; begin id:=0 ; try iA:=strToInt(a) ; inc(id) ; iB:=strtoInt(b) ; result:=iA-iB ; exception if id=0 then begin result:=1;exit ;end ; result:=-1;exit ; end; end; begin repeat I := L; J := R; P := (L + R) shr 1; repeat while (cmpChr(pchr^[I],pchr^[J]))< 0 do Inc(I); while (cmpChr(pchr^[I],pchr^[J]))> 0 do Dec(J); if I <= J then begin ExchangeItems(I, J); if P = I then P := J else if P = J then P := I; Inc(I); Dec(J); end; until I > J; if L < J then QuickSort(L, J, SCompare); L := I; until I >= R; end;
function StringSort(mStr: string; mDesc: Boolean = True): string; var I, J: Integer; T: Char; begin for I := 1 to Length(mStr) - 1 do for J := I + 1 to Length(mStr) do if (mDesc and (mStr[I] > mStr[J])) or (not mDesc and (mStr[I] < mStr[J])) then begin T := mStr[I]; mStr[I] := mStr[J]; mStr[J] := T; end; Result := mStr; end; { StringSort }
procedure TForm1.Button1Click(Sender: TObject); var i,j : integer; str : string; temp : char; begin str := Edit1.Text; for i := 1 to length(str) do begin for j := i+1 to length(str) do begin if str[i] >= str[j] then begin temp:=str[i]; str[i]:=str[j]; str[j]:=temp; end; end; end; Edit1.Text := str; end;end.
function TForm1.OrderNum(StrNum: string): string;
var
i:integer;
j:integer;
LenStr:integer;
StrTemp:Char;
IntTempA:integer;
IntTempB:integer;
begin
LenStr:=Length(StrNum);
for i:=1 to Lenstr do
begin
for j:=I+1 to LenStr do
begin
IntTempA:=StrToInt(StrNum[i]);
IntTempB:=StrToInt(StrNum[j]);
if IntTempA>IntTempB then
begin
StrTemp:=StrNum[i];
StrNum[i]:=StrNum[j];
StrNum[j]:=StrTemp;
end;
end;
end;
result:=StrNum;
end;
var a:Array[1..20] OF real;
temp:real;
i,j:integer;
flag:boolean;
Begin
for i:=1 to 20 do
read(a[i]);
i:=1;
Repeat
flag:=true;
For j:=j to 20-i do
IF a[j]<a[j+1]
Then Begin
temp:=a[j];
a[j]:=a[j+1];
a[j+1]:=temp;
flag:=false;
End ;
i:=i+1;
Until flag;
For i:=1 to 20 do
write(a[j])
END.
sL: TStringList;
s: string;
I: integer;
begin
s := '2142333';
sL := TStringList.Create;
for I:=1 to Length(s) do
sL.Add(s[i]); sL.Sort;
s := sL.Text;
s := StringReplace(s, #13#10, '', [rfReplaceAll]);
FreeAndNil(sL);
showMessage(s);
end;
L:=0;R:=length('2142333');procedure QuickSort(pChr:Pchar;L, R: Integer);
var
I, J, P: Integer;
function cmpChr(a,b:char):integer;
var
strInfo:string ;
iA,iB:integer;
id:integer;
begin
id:=0 ;
try
iA:=strToInt(a) ;
inc(id) ;
iB:=strtoInt(b) ;
result:=iA-iB ;
exception
if id=0 then begin result:=1;exit ;end ;
result:=-1;exit ;
end;
end;
begin
repeat
I := L;
J := R;
P := (L + R) shr 1;
repeat
while (cmpChr(pchr^[I],pchr^[J]))< 0 do Inc(I);
while (cmpChr(pchr^[I],pchr^[J]))> 0 do Dec(J);
if I <= J then
begin
ExchangeItems(I, J);
if P = I then
P := J
else if P = J then
P := I;
Inc(I);
Dec(J);
end;
until I > J;
if L < J then QuickSort(L, J, SCompare);
L := I;
until I >= R;
end;
var
I, J: Integer;
T: Char;
begin
for I := 1 to Length(mStr) - 1 do
for J := I + 1 to Length(mStr) do
if (mDesc and (mStr[I] > mStr[J])) or (not mDesc and (mStr[I] < mStr[J])) then begin
T := mStr[I];
mStr[I] := mStr[J];
mStr[J] := T;
end;
Result := mStr;
end; { StringSort }
var
i,j : integer;
str : string;
temp : char;
begin
str := Edit1.Text;
for i := 1 to length(str) do
begin
for j := i+1 to length(str) do
begin
if str[i] >= str[j] then
begin
temp:=str[i];
str[i]:=str[j];
str[j]:=temp;
end;
end;
end;
Edit1.Text := str;
end;end.
10975037(猩猩),最早回的答案,谢。
aiirii(ari-爱的眼睛) ,创意,用Tstringlist来处理。