首页 > 学院 > 开发设计 > 正文

多项式输出

2019-11-08 02:34:41
字体:
来源:转载
供稿:网友
var a:array[1..100]of longint; i,j,n,last:longint;begin readln(n); for i:=1 to n do read(a[i]); read(last); if (a[1]<>1)and(a[1]<>-1) then begin if a[1]>0 then write(a[1],'x^',n); if a[1]<0 then write(a[1],'x^',n); end; if a[1]=1 then write('x^',n); if a[1]=-1 then write('-x^',n); for i:=2 to n do begin  if (n-i+1)<>1 then  begin   if (a[i]<>1)and(a[i]<>-1) then   begin    if a[i]>0 then write('+',a[i],'x^',n-i+1);    if a[i]<0 then write(a[i],'x^',n-i+1);   end;   if a[i]=1 then write('+x^',n-i+1);   if a[i]=-1 then write('-x^',n-i+1);  end;  if (n-i+1)=1 then  begin   if (a[i]<>1)and(a[i]<>-1) then    begin     if a[i]>0 then write('+',a[i],'x');     if a[i]<0 then write(a[i],'x');    end;   if a[i]=1 then write('+x');   if a[i]=-1 then write('-x');  end; end; if last>0 then write('+',last); if last<0 then write(last);end.
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表