# P1067 polynomial output (string & details)

2021-08-10 08:04:23

## P1067 Polynomial output （ character string & details ）

Subject portal

The question ： Given a dollar n Polynomial of degree n+1 A coefficient of , Output the polynomial .

Ideas ：detail1: Pay attention to judgment an and a0.
detail2: The absolute value of the coefficient is 1 and 0 The situation of .
detail3: And the index is 1 The situation of .
detail4: If it is not the positive number of the first coefficient, add ’+‘

``````#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x;
cin>>n;
string s="";
cin>>x;
if(x>0){ // For the first special judgment
if(x!=1) s+=to_string(x);
}
else if(x<0){
if(x!=-1) s+=to_string(x);
else s+='-';
}
s+="x^"+to_string(n);
for(int i=1;i<n;i++){
cin>>x;
if(!x) continue;
if(x<0){
if(x==-1) s+='-';
else s+=to_string(x);
}
else {
s+='+';
if(x!=1) s+=to_string(x);
}
s+="x";
if(n-i!=1) s+='^'+to_string(n-i);// The special judgment index is 1 The situation of
}
cin>>x;
if(x>0) s+='+'+to_string(x);  // The last item of special judgment .
else if(x<0)  s+=to_string(x);
cout<<s<<endl;
return 0;
}
```

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
```

https://chowdera.com/2021/08/20210810080205555a.html