提交时间:2023-08-22 19:49:39
运行 ID: 99466
#include<bits/stdc++.h> using namespace std; int n; int a[110]; string s; int main() { cin>>n; for(int i=1;i<=n+1;i++) { cin>>a[i]; } if(n==0) { cout<<a[1]; return 0; } if(a[1]<0) { if(a[1]==-1) { cout<<"-"; cout<<"x"; cout<<"^"; cout<<n; } else { cout<<a[1]; cout<<"x"; cout<<"^"; cout<<n; } } else if(a[1]>=1) { if(a[1]==1) { cout<<"x"; cout<<"^"; cout<<n; } else { cout<<a[1]; cout<<"x"; cout<<"^"; cout<<n; } } for(int i=2;i<=n+1;i++) { if(1==n-i+1) { if(a[i]>=1) { cout<<"+"; if(a[i]==1) { cout<<"x"; } else { cout<<a[i]; cout<<"x"; } } else if(a[i]<=-1) { if(a[i]==-1) { cout<<"-"; cout<<"x"; } else { cout<<a[i]; cout<<"x"; } } } else if(i<=n) { if(a[i]>=1) { cout<<"+"; if(a[i]==1) { cout<<"x"; cout<<"^"; cout<<n-i+1; } else { cout<<a[i]; cout<<"x"; cout<<"^"; cout<<n-i+1; } } else if(a[i]<=-1) { if(a[i]==-1) { cout<<"-"; cout<<"x"; cout<<"^"; cout<<n-i+1; } else { cout<<a[i]; cout<<"x"; cout<<"^"; cout<<n-i+1; } } } else { if(a[i]>=1) { cout<<"+"; cout<<a[i]; } else if(a[i]<=-1) { cout<<a[i]; } } } return 0; }