注意点:
- 可以使用OOP的思想.
- 应当认真理解题目限制条件.
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
const int MAXN=5e3;
int cnt;
void printX(int val,int num,bool isFirst){
if(val==0)return;
if(val>0&&(!isFirst))printf("+");
if(abs(val)==1){
if(val<0)printf("-");
if(num==1){
printf("x");
}else{
printf("x^%d",num);
}
}else{
if(num==1){
printf("%dx",val);
}else{
printf("%dx^%d",val,num);
}
}
}
int a[MAXN];
int main(){
int n;
scanf("%d",&n);
cnt=n;
if(n==0)return 0;
for(int i=1;i<=n+1;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++){
bool isFirst=(i==1);
printX(a[i],cnt,isFirst);
cnt--;
}
if(a[n+1]>0)printf("+");
if(a[n+1]!=0)printf("%d",a[n+1]);
printf("\n");
return 0;
}