• 【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.
    
    
  • 相关阅读:
    数组循环三种方式
    PHP上传RAR压缩包并解压目录
    把session写到数据库中
    PHP错误处理方式
    PHP异常处理机制
    css文字的强制换行和超出宽度省略变成点儿
    Mybatis之@Provider的使用方式
    rsync+ssh 枯木
    RHEL6下squid代理之正向代理 枯木
    MySQL体系结构 枯木
  • 原文地址:https://www.cnblogs.com/zyx-crying/p/9319570.html
Copyright © 2020-2023  润新知