-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1720.cpp
48 lines (48 loc) · 1.04 KB
/
1720.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
#include <iostream.h>
void main ()
{
int a[9],i,num;
while (cin>>a[0])
{for (i=1;i<9;i++)
{
cin>>a[i];
}
for (i=0;i<9;i++)
{
if (a[i]!=0) break;
}
if (i==9) num=i-1;
else num=i;
if (a[num]==1&&num!=8) {if (num==7)cout<<"x";else cout<<"x^"<<8-num;}
else if (a[num]==-1&&num!=8) {if (num==7)cout<<"-x";else cout<<"-x^"<<8-num;}
else if (a[num]<-1||a[num]>1) cout<<a[num]<<"x^"<<8-num;
if (num==8) {cout<<a[num];goto loop;}
for (i=num+1;i<8;i++)
{
if (i==7)
{
if (a[i]!=0)
{
if (a[i]>1) {cout<<" + "<<a[i]<<"x";continue;}
if (a[i]<-1) {cout<<" - "<<-a[i]<<"x";continue;}
if (a[i]==1) {cout<<" + x";continue;}
if (a[i]==-1) {cout<<" - x";continue;}
}
}
if (a[i]==0) continue;
else if(i!=7)
{
if (a[i]>1) {cout<<" + "<<a[i]<<"x^"<<8-i;continue;}
if (a[i]<-1) {cout<<" - "<<-a[i]<<"x^"<<8-i;continue;}
if (a[i]==1) {cout<<" + x^"<<8-i;continue;}
if (a[i]==-1) {cout<<" - x^"<<8-i;continue;}
}
}
if (a[8]!=0)
{
if (a[8]>0) cout<<" + "<<a[8];
else cout<<" - "<<-a[8];
}
loop:cout<<endl;
}
}