题目: |
program test03;
var
n,c,i,j,t,temp:integer;
a:array[1..50] of integer;
begin
readln(n);
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do
begin
c:=a[i];t:=i;
for j:=i+1 to n do if c<a[j] then begin t:=j;c:=a[j];end;
if t<>i then begin temp:=a[i];a[i]:=a[t];a[t]:=temp;end;
end;
for i:=1 to n do write(a[i],' ');
end.
输入:
18
90 12 33 44 77 29 8 3 4 6 2 1 21 24 23 54 53 25
输出:90 77 54 53 44 33 29 25 24 23 21 12 8 6 4 3 2 1
|