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

Niaz
Learning poster
Posts: 77
Joined: Fri Dec 17, 2004 11:06 am
Location: East West University, Dhaka, Bangladesh
Contact:

Post by Niaz » Tue Dec 06, 2005 7:03 pm

This part of my code will be....

Code: Select all

else if(coeff[i]<0) 
         { 
            if(k==0) 
               printf("-"); 
            else 
               printf(" - "); 
            coeff[i]=coeff[i]*(-1); 
            if(coeff[i]!=1) 
               printf("%dx",coeff[i]); 
            printf("x"); 
            k=1; 
         }
This

Code: Select all

else if(coeff[i]<0) 
         { 
            if(k==0) 
               printf("-"); 
            else 
               printf(" - "); 
            coeff[i]=coeff[i]*(-1); 
            if(coeff[i]!=1) 
               printf("%dx",coeff[i]); 
            else
               printf("x"); 
            k=1; 
         }
Just a missing of ELSE ! Oh God... I sufferd almost for 3 years with this mistake. No one could give an input like 0 0 0 0 0 0 0 -2 0 ... huh...

Thanks Roby. Thanks a looooooooottttttttttt.
Please join The ACM Solver Group at Yahoo
http://groups.yahoo.com/group/acm_solver/

sds1100
Learning poster
Posts: 95
Joined: Sat Dec 10, 2005 2:09 pm

Help me Acm 392 WA

Post by sds1100 » Sun Dec 11, 2005 9:58 am

i got ac
Last edited by sds1100 on Sun Jan 08, 2006 8:43 am, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Wed Dec 14, 2005 11:22 pm

There can be inputs like..

Input:

Code: Select all

0 0 0 0 0 0 0 -1 -1
Output:

Code: Select all

-x - 1
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

sds1100
Learning poster
Posts: 95
Joined: Sat Dec 10, 2005 2:09 pm

thanks!!!.

Post by sds1100 » Thu Dec 15, 2005 3:55 am

i got AC.
8) :D :) :lol: :P :wink: :roll:

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

392

Post by abhi » Wed Dec 21, 2005 12:36 pm

i am getting WA ......can anyone tell where my prog produces wrong o/p

Code: Select all


code DELETED
Last edited by abhi on Sat Dec 24, 2005 7:03 am, edited 1 time in total.

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

392 - PE

Post by abhi » Thu Dec 22, 2005 5:15 am

now i get PE for the same code ......... i dont understand.......

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

Re: 392 - PE

Post by mamun » Thu Dec 22, 2005 9:33 am

abhi wrote:now i get PE for the same code ......... i dont understand.......
You're printing an extra space at the end of line when the coefficient of 0th degree x is 0.

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi » Thu Dec 22, 2005 12:22 pm

i have changed my code a bit but still PE ...

Code: Select all

code DELETED
Last edited by abhi on Sat Dec 24, 2005 7:03 am, edited 1 time in total.

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

Post by mamun » Thu Dec 22, 2005 2:32 pm

You've taken care of the last co-efficient only. What about others? Try to output the following input in a file and you wiil see trailing space from 3rd line onwards.

Code: Select all

1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 0 0
1 1 1 1 1 1 0 0 0
1 1 1 1 1 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi » Fri Dec 23, 2005 3:02 pm

here is the modified code . it doesnt leave any trailing spaces.still PE???


code DELETED by abhi.
Last edited by abhi on Sat Dec 24, 2005 7:02 am, edited 1 time in total.

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

Post by mamun » Fri Dec 23, 2005 7:11 pm

Output of

Code: Select all

0 0 0 0 0 0 0 0 -1
should be

Code: Select all

-1
Don't forget to remove your codes once you get accepted.

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi » Sat Dec 24, 2005 7:01 am

thanks a lot !!!!! this problem set had a lot of tricky inputs :wink: . but i got AC in 0.500. wat method have you used to solve this prob ????

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

Post by mamun » Sat Dec 24, 2005 1:33 pm

abhi wrote:wat method have you used to solve this prob ????
My code is much shorter than yours. But it ran longer. :D That is because I used abs() function a lot.

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi » Tue Dec 27, 2005 2:10 pm

wat is the method to shorten the code ?
it was frustrating to write such a big code for a problem that seems to be quite simple :evil:

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

392 CE plz hlp me

Post by Munni » Tue Jan 03, 2006 5:27 pm

Hi, ACM prblm solver, plzhlp me by solving my error .I hv tested for all possible i/o.
/*Here is my code*/

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

int main(void)
{
int i=0,a,m;
int arr[10];
float num;
char str[100]="0",tmp[5];
while(cin>>a)
{
arr=a;
if(i==8)
{
for(int j=0,k=0;j<=i;j++)
{
if(arr[j]==0)
continue;
else
{
if(arr[j]<0)
{
str[k]='-';
k++;
str[k]=' ';
k++;
arr[j]*=-1;
}
else
{
if(k!=0)
{
str[k]='+';
k++;
str[k]=' ';
k++;

}



}
if(j==8)
{
if(arr[j]>=10)
{
m=0;
strcpy(tmp," ");
while(arr[j]>0)

{

a=arr[j]%10;
tmp[m]=a+'0';
m++;

num=arr[j]/10;
arr[j]=(int)num;
}
for(int n=m-1;n>=0;n--)
{
str[k]=tmp[n];
k++;
}
break;
}
else

{
str[k]=arr[j]+'0';
k++;
break;
}



}

if(arr[j]!=1)
{
if(arr[j]>=10)
{
m=0;
strcpy(tmp," ");
while(arr[j]>0)

{

a=arr[j]%10;
tmp[m]=a+'0';
m++;
num=arr[j]/10;
arr[j]=(int)num;
}
for(int n=m-1;n>=0;n--)
{
str[k]=tmp[n];
k++;
}
}
else

{
str[k]=arr[j]+'0';
k++;
}

}
if(j<=7)
{
str[k]='x';
k++;
}
if(j<7)
{
str[k]='^';
k++;
str[k]=(8-j)+'0';
k++;
}

str[k]=' ';
k++;






}



}

i=0;
str[++k]='\0';
cout<<str;
strcpy(str,"0");
cout<<"\n";

}
else
i++;




}





return 0;






}

Post Reply

Return to “Volume 3 (300-399)”