提交时间:2023-08-22 14:31:46

运行 ID: 99251

#include<bits/stdc++.h> using namespace std; int n; int a[1000001]; int main(){ cin>>n; n++; for(int i=1;i<=n;i++){ cin>>a[i]; } if(n==1){ cout<<a[1]<<endl; return 0; } for(int i=1;i<n;i++){ if(a[i]==0) continue; if(a[i]>0&&i!=1) cout<<"+"; if(a[i]==1){ if(i==n-1) cout<<"x"; else cout<<"x^"<<n-i; } else if(a[i]==-1){ if(i==n-1) cout<<"-x"; else cout<<"-x^"<<n-i; } else{ if(i==n-1) cout<<a[i]<<"x"; else cout<<a[i]<<"x^"<<n-i; } } if(a[n]!=0) { if(a[n]>0){ cout<<"+"<<a[n]; } else{ cout<<a[n]; } } return 0; }