392 - Polynomial Showdown

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 392 WA

Post by sazzadcsedu »

First Ans-
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
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
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
shantanu18
New poster
Posts: 22
Joined: Tue Jul 20, 2010 9:55 pm

Re: 392 - Polynomial Showdown PE -- plz help

Post by shantanu18 »

I found the bug of my code. When all input is 0 then output is 0. I missed that. Now AC!

Code: Select all

Got AC
al7ssan
New poster
Posts: 1
Joined: Wed Sep 21, 2011 6:03 am

Re: 392 WA

Post 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 :-?
Gator
New poster
Posts: 3
Joined: Wed May 29, 2013 8:28 am

Re: 392 - Polynomial Showdown

Post 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.
Post Reply

Return to “Volume 3 (300-399)”