P1067 [NOIP2009 普及组] 多项式输出 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
解题思路
1.如果n 为0,要特殊判断
2.如果n不为0,特殊判断第一项和最后两项
3.如果系数为0,不输出
4.特殊判断1和-1,注意:如果不是第一项,正整数前要加加号,倒数第二项不输出指数,最后一项只输出系数
代码
#include<bits/stdc++.h>
using namespace std;
int a[105];//创建数组
int main()
{
int n,num=1;
cin>>n;//输入多项式的次数
for(int i=1;i<=n+1;i++)
{
cin>>a[i];//输入系数
}
if(n==0)
{
cout<<a[1];
return 0;
}//特殊判断0
if(a[1]==1)
{
cout<<"x"<<"^"<<n;
}
if(a[1]=&#