Page 7 of 7
Re: 392 WA
Posted: Sat Jan 08, 2011 9:22 pm
by sazzadcsedu
First Ans-
There exist a thread for problem no. 392.So why you are creating a new thread.
And then try this-
your output:-
Code: Select all
-x^8 - x^7 + x^6 + x^5 + x^4 + x^3
Actual output:-
Code: Select all
-x^8 - x^7 + 2x^6 + 3x^5 + 4x^4 + 5x^3
Re: 392 - Polynomial Showdown PE -- plz help
Posted: Mon Jun 20, 2011 11:00 pm
by shantanu18
I found the bug of my code. When all input is 0 then output is 0. I missed that. Now AC!
Re: 392 WA
Posted: Wed Sep 21, 2011 6:14 am
by al7ssan
I'm getting WA with 392 problem.
I had tried every test case and the output is correct . I don't know where is the wrong.
Here is my code, please help
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 ;
}
please help

Re: 392 - Polynomial Showdown
Posted: Mon Oct 12, 2015 8:53 am
by Gator
I think the input for this problem can have leading spaces. As soon as I did a String.trim() on the input line in Java I got AC.