题目: |
program Programg4;
var m,n,i,j:integer;
p,w,a,b:array[0..19] of integer;
begin
read(n); m:= 0;
for i:= 0 to n-1 do
begin read (p[i]); b[i] :=1; end;
for i := 0 to n-1 do
begin
if (i>0) then
a[m]:= p[i]-p[i-1]
else
a[m]:= p[i];
m:= m+1:
while ((m>1) and (a[rn-1]=0)) do
begin m := m-1; b[m] := l; end;
if (m>0) then
w[i]:=b[m-1]
else
w[i]:=b[0];
a[m-1] := a[m-1]-1;
for j := 0 to m-1 do b[j] := b[j]+1;
while ((m>1) and (a[m-1]=0)) do
begin
m := m-1; b[m] :=1;
end;
end;
for i := 0 to n-1 do
begin
write(w[i]); write(' ');
end;
writeln(' ');
end.
输入:9
4 6 6 6 6 8 9 9 9 输出:1 1 2 4 5 1 1 3 9
|