which part of my dynamic is wrong ???
Posted by
Saber 19 Feb 2003 20:15
here is my programm
thanx
{1112}
var
n,i,j,temp : integer;
a : array[1..100,1..2] of integer;
b : array[1..100,0..100,1..2] of integer;
begin
readln(n);
for i :=1 to n do
begin
readln(a[i,1],a[i,2]);
if a[i,1]>a[i,2] then
begin
temp:=a[i,2];
a[i,2]:=a[i,1];
a[i,1]:=temp;
end;
end;
a[n+1,1]:=1000;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i,1]>a[j,1] then
begin
temp:=a[i,1];
a[i,1]:=a[j,1];
a[j,1]:=temp;
temp:=a[i,2];
a[i,2]:=a[j,2];
a[j,2]:=temp;
end;
b[n,0,1]:=1;b[n,1,1]:=a[n,1];b[n,1,2]:=a[n,2];
for i:=n-1 downto 1 do
begin
temp:=a[i,2];j:=i+1;
while (temp>a[j,1]) and (i<n+1) do inc(j);
if (j=n+1) then
begin
b[i,0,1]:=1;b[i,1,1]:=a[i,1];b[i,1,2]:=a[i,2];
end
else
begin
for temp:=1 to b[j,0,1] do
begin
b[i,temp,1]:=b[j,temp,1];
b[i,temp,2]:=b[j,temp,2];
end;
b[i,0,1]:=b[j,0,1]+1;
b[i,b[i,0,1],1]:=a[i,1];
b[i,b[i,0,1],2]:=a[i,2];
end;
end;
j:=1;temp:=-1;
for i:=1 to n do
if b[i,0,1]>temp then
begin
temp:=b[i,0,1];
j:=i;
end;
writeln(b[j,0,1]);
for i:=b[j,0,1] downto 1 do
writeln(b[j,i,1],' ',b[j,i,2]);
end.