题意:输出多项式
解答:模拟输出即可
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
bool fh = 0;
for (int i = n; i >= 0; i--) {
int x;
cin >> x;
if (x == 0) continue;
if (x != 0) {
if (fh == 0) fh = 1;
else if (x > 0) cout << "+";
}
//最后一个位置
if (i == 0) cout << x << '\n';
//第一个位置
else if (i == 1) {
if (x == 1) cout << "x";
else if (x == -1) cout << "-x";
else cout << x << "x";
}
else {
if (x == 1) cout << "x^" << i;
else if (x == -1) cout << "-x^" << i;
else cout << x << "x^" << i;
}
}
return 0;
}
注意:首先最开始是正数不用输出"+",还有就是x的1次方不用输出^1。