392 - Polynomial Showdown
Moderator: Board moderators
-
- 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.
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.
-
- Learning poster
- Posts: 99
- Joined: Sun Apr 06, 2003 5:53 am
- Location: Dhaka, Bangladesh
- 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?
-
- 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!
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!!!!!!!!!!!!
#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!!!!!!!!!!!!
-
- 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
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';
}
}
-
- New poster
- Posts: 7
- Joined: Fri Mar 02, 2007 10:20 am
WA of 392
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;
}
#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;
}
Don't create a new thread if there is one already..
http://online-judge.uva.es/board/viewtopic.php?t=1987
http://online-judge.uva.es/board/viewtopic.php?t=1987
-
- Learning poster
- Posts: 53
- Joined: Sat Jul 29, 2006 7:33 am
- Location: (CSE,DU), Dhaka,Bangladesh
Presentaion error 392(plynomial showdown)
plz help me why i am facing presentation error
advanced thanks to you.
Code: Select all
the code is removed after AC.
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
with best regards
------------------------
ishtiaq ahmed