题目链接:https://www.luogu.org/problemnew/show/P1067
题目代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s; cin >> n;
for (int i = n; i >= 0; i--) {
cin >> s;
if (s == 0) continue;
if (i == n) {
if (s == 1 || s == -1) printf ("%s^%d", s == 1 ? "x" : "-x", i);
else printf ("%dx^%d", s, i);
}
else if (i == 1) {
if (s == 1 || s == -1) printf ("%s", s == 1 ? "+x" : "-x");
else {
if (s > 0) printf ("+%dx", s);
else printf ("%dx", s);
}
}
else if (i == 0) {
if (s == 1 || s == -1) printf ("%s1", s == 1 ? "+" : "-");
else {
if (s > 0) printf ("+%d", s);
else printf ("%d", s);
}
}
else {
if (s == 1 || s == -1) printf ("%s^%d", s == 1 ? "+x" : "-x", i);
else {
if (s > 0) printf ("+%dx^%d", s, i);
else printf ("%dx^%d", s, i);
}
}
}
return 0;
}