显示代码纯文本
//NOIP2009
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int n,i,a,b,j,c[110],i1;
freopen("poly.in","r",stdin);
freopen("poly.out","w",stdout);
scanf("%d",&n);
for (i=n;i>=0;i--)
{
scanf("%d",&a);
if (a==0) continue;
else if (i==n)
{
if (a<0) printf("-");
a=abs(a);
i1=1;
if (a>1)
{
while (a>=1)
{
b=a%10;
c[i1]=b;
i1++;
a=a/10;
}
for (j=i1-1;j>0;j--) printf("%d",c[j]);
}
printf("x^%d",n);
}
else if ((a!=0)&&(i!=0))
{
if (a<0) printf("-");
else printf("+");
a=abs(a);
if (a==1)
{
printf("x");
if (i!=1) printf("^%d",i);
}
else
{
i1=1;
while (a>=1)
{
b=a%10;
c[i1]=b;
i1++;
a=a/10;
}
for (j=i1-1;j>0;j--) printf("%d",c[j]);
printf("x");
if (i!=1) printf("^%d",i);
}
}
else if (i==0)
{
if (a>0) printf("+%d",a);
else printf("%d",a);
}
}
fclose(stdin);
fclose(stdout);
return 0;
}