多项式输出
直接模拟:
#include<iostream> using namespace std; int a[1000]; int n; int main(){ cin >> n; for (int i = n; i >= 0; --i)cin >> a[i]; for (int i = n; i > 0; --i){ if (a[i] == 0)continue; else{ if (a[i] == 1&&i!=n){ cout << "+"; } else if (a[i] == -1){ cout << "-"; } else if (a[i] > 0&&a[i]!=1){ if(i!=n)cout << "+";cout<< a[i]; } else if (a[i] < 0){ cout << a[i]; } if(i>=2)cout << "x^" << i; else cout << 'x'; } } if (a[0] != 0){ if (a[0]>0)cout << "+"; cout << a[0]; } cout << endl; }