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

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Tue Jan 03, 2006 5:48 pm

You're using k outside of its scope which you've declared in a for loop.
Always use double in place of float to get rid of precision error.

Munni
New poster
Posts: 9
Joined: Tue Jan 03, 2006 4:59 pm

Post by Munni » Thu Jan 05, 2006 7:49 pm

hi, solver.Thnx for giving te solution.But i m still in danger with this code.Now this is giving WA.plz hlp.......

L I M O N
Learning poster
Posts: 58
Joined: Wed Dec 31, 2003 8:43 am
Location: Dhaka, Bangladesh
Contact:

Post by L I M O N » Fri Jan 06, 2006 4:36 pm

try those :
0 0 0 0 0 0 0 0 -1
0 0 0 0 0 0 -5 1 0

output should be
-1
-5x^2 + x

// note that there is no space between '-' sing and number, if the output begins with '-' sing

Pasa Yildirim
New poster
Posts: 14
Joined: Mon Mar 07, 2005 7:10 pm
Location: Bosnia and Herzegovina
Contact:

392 WA

Post by Pasa Yildirim » Sun Jan 15, 2006 8:21 pm

Hello!

What is wrong with my code?

It passes all test data I found on this forum.

Code: Select all

REMOVED
Last edited by Pasa Yildirim on Mon Jan 16, 2006 8:30 pm, edited 1 time in total.

Solaris
Learning poster
Posts: 99
Joined: Sun Apr 06, 2003 5:53 am
Location: Dhaka, Bangladesh
Contact:

Post by Solaris » Mon Jan 16, 2006 7:09 pm

Change your input part to the following code and u will get AC.. I guess there may be some extra characters after the last test case in the judge data.

Code: Select all

while (cin >> niz[0])
   {
      for (int i = 1; i < 9; i++)
		  cin >> niz[i];
Where's the "Any" key?

Pasa Yildirim
New poster
Posts: 14
Joined: Mon Mar 07, 2005 7:10 pm
Location: Bosnia and Herzegovina
Contact:

Thank you!

Post by Pasa Yildirim » Mon Jan 16, 2006 8:29 pm

I got AC! Thank you very much, Solaris!

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

392 WA??????????????

Post by sakhassan » Sun Mar 26, 2006 11:44 am

#include<stdio.h>
#include<string.h>
#include<math.h>


void output(int poly, int i)
{
if(i>1)
{
if(abs(poly)==1)
printf("x^%d",i);
else
printf("%dx^%d",abs(poly),i);

}
else if(i==1)
{
if(abs(poly)==1)
printf("x");
else
printf("%dx",abs(poly));
}
else
{
if( abs(poly) == 1)
printf("1");
else
printf("%d",abs(poly));
}
}

int main()
{

int poly;
int flag,start;
int i;
flag = 0;

while(1)
{

start = 0;
for(i=8;i>=0;i--)
{
if(scanf("%d",&poly)!=1)
{
flag = 1;
break;
}

if(poly && !start)
{
if(poly<1)
printf("-");
output(poly,i);
start=1;
}
else if(poly)
{
if(poly<=-1)
{
printf(" - ");
output(poly,i);
}
else
{
printf(" + ");
output(poly,i);
}

}

}
if( !start)
printf("0");
printf("\n");
if(flag)
break;

}
return 0;
}

Whats wrong?? I cant find it!!!!!!!!!!!!

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post by sakhassan » Wed Mar 29, 2006 10:29 am

At last I got the mistake... :lol:
it was printing an extra 0 after the final input.....

if( !start)
printf("0");
printf("\n");
if(flag)
break;

----->

printf("\n");
if(flag)
break;
if( !start)
printf("0");

will be like this !!!!!!!!!!!!! :oops:

vinit_iiita
New poster
Posts: 30
Joined: Mon Jun 19, 2006 10:37 pm
Contact:

Post by vinit_iiita » Mon Jul 24, 2006 10:09 pm

Code: Select all

#include<iostream>

using namespace std;
int main()
{
    int a[9];
    while (cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]>>a[7]>>a[8])
    {
          bool flag=false;
          int i;
          for (i=0;i<7;i++)
          {
              if (a[i]!=0 && flag==false)
              {
                  
                  if(a[i]==1)
                  cout<<"x^"<<8-i<<" ";
                  else if(a[i]==-1)
                  cout<<"-x^"<<8-i<<" ";
                  else if(a[i]!=1 && a[i]!=-1)
                  cout<<a[i]<<"x^"<<8-i<<" ";
                  flag=true;
                  }
                  else if(a[i]!=0 && flag==true)
                  {
                       if(a[i]==1)
                       cout<<"+ x^"<<8-i<<" ";
                       else if(a[i]==-1)
                       cout<<"- x^"<<8-i<<" ";
                       else if(a[i]>1)
                       cout<<"+ "<<a[i]<<"x^"<<8-i<<" ";
                       else if(a[i]<-1)
                       cout<<"- "<<-1*a[i]<<"x^"<<8-i<<" ";
                       }
                       }
                       if(flag==false)
                       {if(a[7]==1)
                       cout<<"x ";
                       else if(a[7]==-1)
                       cout<<"-x ";
                       else if(a[7]>0)
                       cout<<a[7]<<"x ";
                       else if(a[7]<0)
                       cout<<"-"<<-1*a[7]<<"x ";
                       if(a[7]!=0)
                       flag=true;
                       }
                       else if(flag)
                       {if(a[7]==1)
                       cout<<"+ x ";
                       else if(a[7]==-1)
                       cout<<"- x ";
                       else if(a[7]>0)
                       cout<<"+ "<<a[7]<<"x ";
                       else if(a[7]<0)
                       cout<<"- "<<-1*a[7]<<"x ";
                       }
                       if(flag==false)
                       {
                       if(a[8]>0)
                       cout<<a[8];
                       else if(a[8]<0)
                       cout<<"-"<<-1*a[8];
                       
                       }
                       else if(flag)
                       {
                       if(a[8]>0)
                       cout<<"+ "<<a[8];
                       else if(a[8]<0)
                       cout<<"- "<<-1*a[8];
                       
                       }
                       cout<<endl;
                       }
                       return 0;
                       }

Why WA.........................
plz find out the bug this problem is frustating me.... :cry:

[/b]
win

Sayeef
New poster
Posts: 12
Joined: Sun Jun 18, 2006 3:06 am

I keep getin P.E for 392 plz help

Post by Sayeef » Tue Jan 02, 2007 5:54 pm

This is the code can anyone tell me why I keep getting PE?

Code: Select all

#include<iostream>
using namespace std;
int abs(int x)
{
	if(x>=0)
		return x;
	return -x;
}
void main()
{
	int poly[9]={0},i=0,flag,p;
	while(cin>>poly[0])
	{
		
			flag=0;
			for(i=1;i<9;i++)
			{	
				cin>>poly[i];
			}
			
			for(i=0;i<9;i++)
			{
			if(poly[i]<0&&flag)
				cout<<'-'<<' ';
			else if(poly[i]<0&&!flag)
				cout<<'-';
			else if(poly[i]>0&&flag!=0)
				cout<<'+'<<' ';
			poly[i]=abs(poly[i]);
			if(poly[i]>1&&i!=8)
				cout<<poly[i];
			if(poly[i])
			{
				p=8-i;
				if(p)
				{
					cout<<'x';
					flag=1;
					if(p>1)
					cout<<'^'<<(8-i)<<' ';
					else
						cout<<' ';
				}
				else
				{
					cout<<poly[i];
					flag=1;
				}
			}

			}
			if(!flag)cout<<'0';
			cout<<'\n';
	}
			
}

User avatar
Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 pm

Post by Spykaj » Tue Jan 02, 2007 9:00 pm

Try replace all spaces to underlines and test sample input/output ;p

x^5_+_22x^4_-_333x^3_+_x_-_1
-55x^2_+_5x_
O,here is bug^ :)

Md.Arafat Hossain
New poster
Posts: 7
Joined: Fri Mar 02, 2007 10:20 am

WA of 392

Post by Md.Arafat Hossain » Mon Mar 05, 2007 7:51 pm

Why WA,please help me.

#include<iostream.h>
int main()
{

int a,count=9,i=0,p=0,c=0;
char y='x';

while(cin>>a){
i++;

if(a>0){
if(p==0){
if(i==9)
cout<<a;
else
{ if(a!=1)
cout<<a;}
p=1;}

else
{ cout<<'+'<<" ";
if(a!=1)
cout<<a;}

}

else if(a<0)
{ cout<<'-'<<" ";
a=-a;
if((a!=1)||(i==9))
cout<<a;
c++;}



if(a!=0){
if((count-i)!=0)
cout<<y;
if((count-i)>1)
cout<<'^'<<count-i;
cout<<" ";
p=1;}

if(i==9){
if(c==0)
cout<<a;
i=0;
cout<<endl;
p=0;}



}
return 0;
}

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Tue Mar 06, 2007 2:45 am

Don't create a new thread if there is one already..

http://online-judge.uva.es/board/viewtopic.php?t=1987

ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

Presentaion error 392(plynomial showdown)

Post by ishtiaq ahmed » Tue Mar 20, 2007 11:13 am

plz help me why i am facing presentation error

Code: Select all

the code is removed after AC.
advanced thanks to you.
Last edited by ishtiaq ahmed on Wed Mar 21, 2007 12:49 pm, edited 1 time in total.
No venture no gain

with best regards
------------------------
ishtiaq ahmed

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Tue Mar 20, 2007 12:12 pm

I did not run your code, but check for extra spaces at the end of a line.

Post Reply

Return to “Volume 3 (300-399)”