标签:输出 names printf mes -- name std main for
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[109];
int main()
{
int n,i;
scanf("%d",&n);
for(i=n;i>=0;i--) scanf("%d",&a[i]);
for(i=n;i>1;i--)
{
if(a[i]==0) continue;
if(i==n) {
if(a[i]!=1&&a[i]!=-1){
printf("%dx^%d",a[i],i);
continue;
}
else if(a[i]==1){
printf("x^%d",i);
continue;
}
else if(a[i]==-1){
printf("-x^%d",i);
continue;
}
}
else if(a[i]>0) printf("+");
if(a[i]==1)
{
printf("x^%d",i);
continue;
}
else if(a[i]==-1)
{
printf("-x^%d",i);
continue;
}
else printf("%dx^%d",a[i],i);
}
if(a[1]==1) printf("+x");
else if(a[1]>0&&a[1]!=1) printf("+%dx",a[1]);
else if(a[1]==-1) printf("-x");
else if(a[1]<0&&a[1]!=-1) printf("%dx",a[1]);
if(a[0]>0) printf("+%d",a[0]);
else if(a[0]<0) printf("%d",a[0]);
return 0;
}
标签:输出 names printf mes -- name std main for
原文地址:https://www.cnblogs.com/EchoZQN/p/9995871.html