#include<iostream>
using namespace std;
int main(){
int n, s;
cin >> n;
for(int i=n;i>=0;i--){
cin >> s;
if(s){
if(i!=n && s>0) cout << '+';
else if(s<0) cout << '-';
if(abs(s) != 1 || !i) cout << abs(s);
if(i) cout << 'x';
if(i>1) cout << '^' << i;
}
}
}
由于题目说第一项一定非0,所以我们考虑贪心,边读入边输出
只不过需要考虑的因素比较多。

京公网安备 11010502036488号