python

P1067 [NOIP2009 普及组] 多项式输出

Orz
by int64 @ 2021-08-27 08:53:56


参考一下我的(~~绝对不是因为我没能力帮别人改代码~~) ```python a=int(input()) b=list(map(int,input().split())) c=0 d=0 for e in range(a+1): if b[e-d]==0 and c==0: del b[e-d] d+=1 else: c=1 a=len(b)-1 for f in range(a+1): g=a-f if f==a: if b[f]>=1: if f>=1: print(f'+{b[f]}') else: print(f'{b[f]}') elif b[f]<=-1: print(b[f]) elif f==0: if g==1: if b[f]==1: print('x',end='') elif b[f]==-1: print('-x',end='') elif b[f]!=0: print(f'{b[f]}x',end='') else: if b[f]==1: print(f'x^{g}',end='') elif b[f]==-1: print(f'-x^{g}',end='') elif b[f]!=0: print(f'{b[f]}x^{g}',end='') else: if g==1: if b[f]==1: if f>=1: print('+x',end='') else: print('x',end='') elif b[f]==-1: print('-x',end='') elif b[f]>=1: if f>=1: print(f'+{b[f]}x',end='') else: print(f'{b[f]}x',end='') elif b[f]<=-1: print(f'{b[f]}x',end='') else: if b[f]==1: if f>=1: print(f'+x^{g}',end='') else: print(f'x^{g}',end='') elif b[f]==-1: print(f'-x^{g}',end='') elif b[f]>=1: if f>=1: print(f'+{b[f]}x^{g}',end='') else: print(f'+{b[f]}x^{g}',end='') elif b[f]<=-1: print(f'{b[f]}x^{g}',end='') ```
by blsya23a2 @ 2023-06-22 22:38:25


|