392 - Polynomial Showdown

Moderator: Board moderators

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Contact:
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
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
Contact:
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

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
Contact:
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!

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??????????????

#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
At last I got the mistake...
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 !!!!!!!!!!!!!

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

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

[/b]
win

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

I keep getin P.E for 392 plz help

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';
}

}``````

Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 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

#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

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

ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am

Presentaion error 392(plynomial showdown)

plz help me why i am facing presentation error

Code: Select all

``````the code is removed after AC.
``````