_liujunming_ @ 2024-09-05 16:50:50
代码:
#include<bits/stdc++.h>
using namespace std;
int n,x,a[10005];
bool kkk(int i)
{
if(i==n)return false;
for(int j=1;j<n-i+1;j++)
{
if(a[j]!=0)return true;
}
return false;
}
void out(int i,int j)
{
if(i==0)return ;
if(abs(j)==0)
{
if(i<0)cout<<"-";
else if(kkk(j))cout<<"+";
printf("%d",i);
return ;
}
if(abs(j)==1&&abs(i)==1)
{
if(i<0)cout<<"-";
else if(kkk(j))cout<<"+";
printf("x");
return ;
}
if(abs(j)==1)
{
if(i<0)cout<<"-";
else if(kkk(j))cout<<"+";
printf("%dx",i);
return ;
}
if(abs(i)==1)
{
if(i<0)cout<<"-";
else if(kkk(j)) cout<<"+";
printf("x^%d",j);
return ;
}
if(i<0)printf("-");
else if(kkk(j))printf("+");
printf("%dx^%d",abs(i),j);
}
int main()
{
cin>>n;
for(int i=n;i>=0;i--)
{
cin>>x;
a[n-i+1]=x;
out(x,i);
}
return 0;
}
看着好像也没啥问题啊