37 lines
921 B
C++
37 lines
921 B
C++
|
|
#include <bits/stdc++.h>
|
|||
|
|
|
|||
|
|
using namespace std;
|
|||
|
|
const int N = 110;
|
|||
|
|
|
|||
|
|
//这模拟太啰嗦了~
|
|||
|
|
int main() {
|
|||
|
|
int n;
|
|||
|
|
cin >> n;
|
|||
|
|
int x;
|
|||
|
|
// a[0~n-1]是系数,a[n]是常数
|
|||
|
|
for (int i = 0; i < n; i++) {
|
|||
|
|
cin >> x;
|
|||
|
|
if (x == 0) continue;
|
|||
|
|
|
|||
|
|
if (x < 0) {
|
|||
|
|
if (x == -1)
|
|||
|
|
cout << "-";
|
|||
|
|
else
|
|||
|
|
cout << x; //-1不要输出1,其它的-2,-3等如实输出
|
|||
|
|
} else { // x肯定大于0
|
|||
|
|
if (i > 0) cout << "+"; //第一位前面不能有+号
|
|||
|
|
if (x != 1) cout << x; //系数1不输出,2,3等正常输出
|
|||
|
|
}
|
|||
|
|
if (n - i > 1) cout << "x^" << n - i;
|
|||
|
|
else
|
|||
|
|
cout << "x"; // 1次方特殊
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//常数位
|
|||
|
|
cin >> x;
|
|||
|
|
if (x > 0)
|
|||
|
|
cout << "+" << x;
|
|||
|
|
else if (x < 0)
|
|||
|
|
cout << x;
|
|||
|
|
return 0;
|
|||
|
|
}
|