把模拟ac了
2024-12-24 22:00:04
发布于:上海
0阅读
0回复
0点赞
#include<iostream>
#include<cmath>
using namespace std;
int n;
int a[105];
int main(){
cin>>n;
for(int i=1;i<=n+1;i++){
cin>>a[i];
}
//a[1]
if(a[1]==1) cout<<"x^"<<n;
else if(a[1]==-1) cout<<"-x^"<<n;
else cout<<a[1]<<"x^"<<n;
//a[2]-a[n]
for(int i=2;i<=n;i++){
if(a[i]>0) cout<<"+";
else if(a[i]<0) cout<<"-";
else continue;
a[i]=abs(a[i]);
if(a[i]!=1) cout<<a[i];
cout<<"x";
if(n-i+1!=1) cout<<"^"<<n-i+1;
}
//a[n+1]
if(a[n+1]>0) cout<<"+"<<a[n+1];
else if(a[n+1]<0) cout<<"-"<<abs(a[n+1]);
}
这里空空如也
有帮助,赞一个