提交时间:2024-04-16 16:55:42
运行 ID: 143574
#include<bits/stdc++.h> using namespace std; int n,a[1000001]; int main(){ cin>>n; n++; for(int i=1;i<=n;i++)cin>>a[i]; if(n==1){ cout<<a[1]; 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; }