讨论 / 22就最后一组了 老90 帮忙看看
yao_bc 2010-09-08 21:58:00
点我顶贴 收藏 删除
我的程序

program mars;

var

num:array [1..10000] of integer;

i,j,t,k:integer;

n,m:integer;

function find_min(t:integer):integer;

var

min,i,k:integer;

begin

min:=3000;

for i:=t to n do

if (num[i]<min) and (num[i]>num[t-1]) then

begin

min:=num[i];

k:=i;

end;

find_min:=k;

end;

procedure swap(s,t:integer);

var

tmp:integer;

begin

tmp:=num[s];

num[s]:=num[t];

num[t]:=tmp;

end;

procedure new(s,t:integer);

var

i,tmp:integer;

begin

for i:=s to (s+t) shr 1 do

begin

tmp:=num[i];

num[i]:=num[t-i+s];

num[t-i+s]:=tmp;

end;

end;

begin

assign(input,'mars.in'); reset(input);

assign(output,'mars.out'); rewrite(output);

readln(n);

readln(m);

fillchar(t,sizeof(t),0);

for i:=1 to n do

read(num[i]);

close(input);

for i:=1 to m do

begin

for j:=n-1 downto 1 do

if num[j]<num[j+1] then

begin

t:=j;

break;

end;

k:=find_min(t+1);

swap(t,k);

new(t+1,n);

end;

for i:=1 to n do

write(num[i],' ');

close(output);

end.

查看更多回复
提交回复