|
发表于 2013-5-23 00:07:24
|
显示全部楼层
不知道在哪里上传 只能贴上来让小甲鱼老师指点下,和效率问题
var
a: array of integer;
str,temp: string;
i: integer;
j,x,k: integer;
begin
j:= 0;
str:= Trim(Edit1.Text);
for i:= 1 to length(str) do
begin
if( str[i] = #32 ) then
begin
j:= j + 1; //计算有几个数
end;
end;
i:= 1; x:= 0;
SetLength(a,j+1); //j+1 是因为4个数有3个空格
while( i < length(str) ) do
begin
while((str[i] <> #32) and (str[i] <> #0)) do
begin
temp:= temp + str[i];
i:= i + 1;
end;
i:= i + 1;
a[x]:= strtoint(temp);
x:= x + 1;
temp:= '';
end;
Edit1.Text:= '';
for k:= 1 to j do //排序
for x:= 0 to j-k do
begin
if (a[x]>a[x+1]) then
begin
i:= a[x];
a[x]:= a[x+1];
a[x+1]:= i;
end;
end;
for x:= 0 to j do
Edit1.Text:= Edit1.Text + inttostr(a[x]) + ' ';
end;
end. |
|