【NOIP2016提高A组模拟9.28】求导

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.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值