Description
Input
Output
题解
可以先把多项式拆成很多个单项式,然后分别对于每⼀项求导之后输出。
细节较多,要注意系数为0,系数前正负号,以及指数为0或1的情况。
注意ansistring
代码
var
l:longint;
s:ansistring;
procedure main;
var
i,p,a,b,j,pp:longint;
ss:ansistring;
begin
l:=length(s);
i:=1; j:=0;
while i<l do
begin
ss:=''; pp:=i;
while (s[i]<>'+') and (s[i]<>'-') and (i<=l) do
begin
ss:=ss+s[i];
inc(i);
end;
a:=0; b:=0;
p:=0; p:=pos('x',ss);
if p>0 then val(copy(ss,1,p-1),a)
else begin inc(i); continue; end;
if p=1 then a:=1;
if s[pp-1]='-' then a:=-a;
p:=0; p:=pos('^',ss);
if p>0 then val(copy(ss,p+1,length(ss)-p),b)
else b:=1;
if j=0 then
begin
if b=1 then write(a*b) else
if b-1<>1 then write(a*b,'x^',b-1)
else write(a*b,'x');
end else
begin
if a*b>0 then write('+');
if abs(a*b)<>1 then write(a*b);
if b-1<>0 then write('x');
if b-1>1 then write('^',b-1);
end;
inc(j); inc(i);
end;
if j=0 then write(j);
end;
begin
assign(input,'equation.in');
assign(output,'equation.out');
reset(input);
rewrite(output);
readln(s);
main;
close(input);
close(output);
end.