cjhcjh2011 @ 2024-09-17 19:34:40
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int cnt=n;
int a[105];
if(n==0){
int q;
cin>>q;
cout<<q;
return 0;
}
int tt=0;
for(int i=1;i<=n+1;i++){
cin>>a[i];
tt+=a[i];
}
for(int i=1;i<=n+1;i++){
if(i==n+1){
if(a[n+1]>0){
if(tt==a[n+1]){
cout<<a[n+1];
}
else cout<<'+'<<a[n+1];
}
else if(a[n+1]<0){
cout<<a[n+1];
}
break;
}
else if(i==n){
if(a[i]==0)continue;
else if(a[i]==1){
cout<<"+x";
continue;
}
else if(a[i]==-1){
cout<<"-x";
continue;
}
else if(a[i]>0&&a[i]!=1){
cout<<"+"<<a[i]<<"x";
}
else if(a[i]<0&&a[i]!=-1){
cout<<"-"<<a[i]<<"x";
}
}
else if(i==1){
if(a[1]==0)continue;
if(a[1]==1)cout<<"x^"<<cnt;
else if(a[1]==-1){
cout<<'-'<<"x^"<<cnt;
}
else{
cout<<a[i]<<"x^"<<cnt;
}
}
else{
if(a[i]==0){
continue;
}
else if(a[i]>0){
if(a[i]==1)cout<<"+x^"<<cnt;
else cout<<"+"<<a[i]<<"x^"<<cnt;
}
else if(a[i]<0){
if(a[i]==-1)cout<<"-x^"<<cnt;
else cout<<a[i]<<"x^"<<cnt;
}
}
cnt--;
}
return 0;
}
by cjhcjh2011 @ 2024-09-17 20:01:57
是多项式输出 NOIP2009