program duoxiangshi;
type
link=^node;
node=record
coef :real;
exp :integer;
next :link;
end;
poly=link;
var
p,pa,pb:poly;
procedure jl(var a:poly);
var
p,q :poly;
co :real;
ex :integer;
begin
p:=nil;
repeat
read(co,ex);
new(q);
q^.coef:=co;
q^.exp:=ex;
q^.next:=p;
p:=q;
until (ex=-1) and (co=-1);
a:=p;
readln;
end;
procedure add_poly(var a:poly; b:poly);
var
p,q,u,pre:poly;
x:real;
begin
p:=a^.next;
q:=b^.next;
pre:=a;
while (p<>nil) and (q<>nil) do
if (p^.exp>q^.exp) then
begin
pre:=p;
p:=p^.next;
end
else
if (p^.exp=q^.exp) then
begin
x:=p^.coef+q^.coef;
if (x<>0) then
begin
p^.coef:=x;
pre:=p;
end
else
begin
pre^.next:=p^.next;
dispose(p);
end;
p:=pre^.next;
u:=q;
q:=q^.next;
dispose(u);
end
else
begin
u:=q^.next;
q^.next:=p;
pre^.next:=q;
pre:=q;
q:=u;
end;
if (q<>nil) then
pre^.next:=q;
dispose(b);
end;
begin
jl(pa);
jl(pb);
add_poly(pa,pb);
p:=pa;
p:=p^.next;
while (p<>nil) do
begin
writeln(p^.coef:8:2,p^.exp:5);
p:=p^.next;
end;
end.
posted on 2005-08-19 07:52
李青 阅读(723)
评论(0) 编辑 收藏 引用