python题解
2026-04-05 14:27:31
发布于:江苏
1阅读
0回复
0点赞
n = int(input())
coeffs = list(map(int, input().split())) # 输入系数,顺序是 x^n, x^(n-1)...x^0
res = []
for i in range(n + 1):
c = coeffs[i]
exp = n - i
if c == 0:
continue
if not res:
sign = '-' if c < 0 else ''
else:
sign = '+' if c > 0 else '-'
abs_c = abs(c)
term = ''
if exp == 0:
term = str(abs_c)
elif exp == 1:
if abs_c == 1:
term = 'x'
else:
term = f'{abs_c}x'
else:
if abs_c == 1:
term = f'x^{exp}'
else:
term = f'{abs_c}x^{exp}'
res.append(sign + term)
print(''.join(res))
这里空空如也

有帮助,赞一个