-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduoxiangshi.cpp
68 lines (57 loc) · 1.14 KB
/
duoxiangshi.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
using namespace std;
int main(){
int n;
int a[105];
cin>>n;
int t;
for(int i=n;i>=0;i--){
cin>>t;
a[i]=t;
}
for(int i=n;i>=0;i--){
if(a[i]==1&&i==n){
cout<<"x^"<<i;
}
if(a[i]==-1&&i!=0&&i!=1){
cout<<"-x^"<<i;
}
if(a[i]==1&&i!=0&&i!=n&&i!=1){
cout<<"+x^"<<i;
}
if(a[i]>1&&i==n){
cout<<a[i]<<"x^"<<i;
}
if(a[i]<-1&&i!=0&&i!=1){
cout<<a[i]<<"x^"<<i;
}
if(a[i]>1&&i!=0&&i!=n&&i!=1){
cout<<"+"<<a[i]<<"x^"<<i;
}
if(i==0&&a[i]>0){
cout<<"+"<<a[i];
}
if(i==0&&a[i]<0){
cout<<a[i];
}
if(a[i]==0){
continue;
}
if(n==1){
cout<<a[i]<<"x";
}
if(i==1&&a[i]>1){
cout<<"+"<<a[i]<<"x";
}
if(i==1&&a[i]<-1){
cout<<a[i]<<"x";
}
if(i==1&&a[i]==1){
cout<<"+x";
}
if(i==1&&a[i]==-1){
cout<<"-x";
}
}
return 0;
}