You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
/*
xx
10continue
2'+''-'
31
40x
51
*/
int main() {
int n;
cin >> n; // 一元多项式的次数
bool is_first = true;
for (int i = n; i >= 0; i--) { // 其中第 i 个整数表示第 ni+1 次项的系数
int a;
cin >> a;
if (!a) continue;
if (!is_first && a > 0)
printf("+");
else if (a < 0)
printf("-");
if (abs(a) != 1 || i == 0) printf("%d", abs(a));
if (i) printf("x");
if (i > 1) printf("^%d", i);
is_first = false;
}
return 0;
}