Page 4 of 7

Posted: Tue Dec 06, 2005 7:03 pm
by Niaz
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.

Help me Acm 392 WA

Posted: Sun Dec 11, 2005 9:58 am
by sds1100
i got ac

Posted: Wed Dec 14, 2005 11:22 pm
by Jan
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.

thanks!!!.

Posted: Thu Dec 15, 2005 3:55 am
by sds1100
i got AC.
8) :D :) :lol: :P :wink: :roll:

392

Posted: Wed Dec 21, 2005 12:36 pm
by abhi
i am getting WA ......can anyone tell where my prog produces wrong o/p

Code: Select all


code DELETED

392 - PE

Posted: Thu Dec 22, 2005 5:15 am
by abhi
now i get PE for the same code ......... i dont understand.......

Re: 392 - PE

Posted: Thu Dec 22, 2005 9:33 am
by mamun
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.

Posted: Thu Dec 22, 2005 12:22 pm
by abhi
i have changed my code a bit but still PE ...

Code: Select all

code DELETED

Posted: Thu Dec 22, 2005 2:32 pm
by mamun
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

Posted: Fri Dec 23, 2005 3:02 pm
by abhi
here is the modified code . it doesnt leave any trailing spaces.still PE???


code DELETED by abhi.

Posted: Fri Dec 23, 2005 7:11 pm
by mamun
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.

Posted: Sat Dec 24, 2005 7:01 am
by abhi
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 ????

Posted: Sat Dec 24, 2005 1:33 pm
by mamun
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.

Posted: Tue Dec 27, 2005 2:10 pm
by abhi
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:

392 CE plz hlp me

Posted: Tue Jan 03, 2006 5:27 pm
by Munni
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;






}