标签:
水题一道 不解释了= =
var a:array[0..10000] of longint; n,m,i,j,k,t,x,y:longint; begin readln(n);readln(m); for i:=1 to n do read(a[i]); k:=0; while k<m do begin if a[n-1]<a[n] then begin t:=a[n-1];a[n-1]:=a[n];a[n]:=t; inc(k); end else begin for i:=n-1 downto 2 do if a[i]>a[i-1] then break; t:=maxlongint; for j:=n downto i do if (a[j]<t) and (a[j]>a[i-1]) then begin t:=a[j];x:=j; end; y:=a[i-1];a[i-1]:=a[x];a[x]:=y;inc(k); for x:=i to n-1 do for y:=x+1 to n do if a[x]>a[y] then begin j:=a[x];a[x]:=a[y];a[y]:=j; end; end; end; for i:=1 to n-1 do write(a[i],‘ ‘); write(a[n]); end.
标签:
原文地址:http://www.cnblogs.com/victorslave/p/4823921.html