There exist a thread for problem no. 392.So why you are creating a new thread.
And then try this-
Code: Select all
-1 -1 2 3 4 5 0 0 0
Code: Select all
-x^8 - x^7 + x^6 + x^5 + x^4 + x^3
Code: Select all
-x^8 - x^7 + 2x^6 + 3x^5 + 4x^4 + 5x^3
Moderator: Board moderators
Code: Select all
-1 -1 2 3 4 5 0 0 0
Code: Select all
-x^8 - x^7 + x^6 + x^5 + x^4 + x^3
Code: Select all
-x^8 - x^7 + 2x^6 + 3x^5 + 4x^4 + 5x^3
Code: Select all
Got AC
Code: Select all
# include <iostream>
# include <stdlib.h>
# include <math.h>
using namespace std ;
int main ()
{
//freopen("FILE_NAME_FOR_INPUT.txt","r",stdin);
//freopen("FILE_NAME_FOR OUTPUT.txt","w",stdout);
int j , l , arr[9];
bool b ;
while(cin >> arr[8] >> arr[7] >> arr[6] >> arr[5] >> arr[4] >> arr[3] >> arr[2] >> arr[1] >> arr[0])
{
j = 0 ;
b = false ;
for (int i = 8 ; i >= 0 ; i--)
{
if (arr[i] != 0)
{
b = true ;
if (j == 0 && i != 0)
{
if(arr[i] != 1 && arr[i] != -1)
{
cout << arr[i] ;
}
else if(arr[i] == -1)
{
cout << "-" ;
}
}
else if (j == 0 && i == 0)
{
cout << arr[i] ;
}
else
{
if (arr[i] > 1)
{
cout << " + " << arr[i] ;
}
else if (arr[i] < -1)
{
cout << " - " << arr[i] * (-1) ;
}
else if (arr[i] == 1)
{
cout << " + " ;
}
else if (arr[i] == -1)
{
cout << " - " ;
}
}
if (i != 0)
{
if (i == 1)
{
cout << "x" ;
}
else if (i > 1)
{
cout << "x^" << i ;
}
}
j++ ;
}
}
if (b == false)
cout << 0 ;
cout << endl ;
}
return 0 ;
}