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.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
/*
|
|
|
|
|
从前往后依次处理每一项,依次考虑符号、系数、x、x的次数:
|
|
|
|
|
|
|
|
|
|
1、如果系数是0,则直接continue;
|
|
|
|
|
2、如果不是第一个非零项,且系数是正的,则输出'+';如果系数是负的,则无条件输出'-';
|
|
|
|
|
3、如果系数的绝对值不是1,或者是常数项,则输出系数的绝对值;
|
|
|
|
|
4、如果次数不为0,则输出x
|
|
|
|
|
5、如果次数大于1,则输出次数
|
|
|
|
|
*/
|
|
|
|
|
int main() {
|
|
|
|
|
int n;
|
|
|
|
|
cin >> n; // 一元多项式的次数
|
|
|
|
|
|
|
|
|
|
bool is_first = true;
|
|
|
|
|
for (int i = n; i >= 0; i--) { // 其中第 i 个整数表示第 n−i+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;
|
|
|
|
|
}
|