多项式输出
2021秋算法入门班
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int a[105];
for (int i = n; i >= 0; i--)
{
cin >> a[i];
}
for (int i = n; i >= 0; i--)
{
if (a[i] == 0) continue;
//1.处理符号
if (a[i] > 0 && n == i) {}
if (a[i] > 0 && n != i) cout << "+";
if (a[i] < 0)cout << "-";
//2.处理系数
if (i != 0 && (a[i] == 1 || a[i] == -1)) {}
else cout << abs(a[i]);
//3.处理指数
if (i == 0 || i == 1)
{
if (i == 0) {}
if (i == 1)cout << "x";
}
else cout << "x^" << i;
}
}