题解 | 多项式输出
多项式输出
https://www.nowcoder.com/practice/142ee43d3e7345d385328faca9f636e5
#include <ios>
#include <iostream>
#include<vector>
#include<cmath>
using namespace std;
int main() {
int n,sign=0;
cin>>n;
vector<int>arr;
n+=1;
while(n--){
int temp;
cin>>temp;
if(temp<0)cout<<"-";
else if(sign==1&&temp>0)cout<<"+";
if(n>1){
if(fabs(temp)>1)cout<<fabs(temp)<<"x^"<<n;
else if(fabs(temp)==1)cout<<"x^"<<n;
}
else if(n==1){
if(fabs(temp)>1)cout<<fabs(temp)<<"x";
else if(fabs(temp)==1)cout<<"x";
}
else{
if(temp!=0){
cout<<fabs(temp);
}
}
sign=1;
}
return 0;
}

查看16道真题和解析