392 - Polynomial Showdown
Moderator: Board moderators
problem with 392
Can anyone tell me the reason why i got wrong answer in this problem.Can anyone give some input?
Here is my prograrm:
#include <stdio.h>
#include <math.h>
main()
{
int r,a[10],i,cnt;
while(1)
{
cnt =0;
r=scanf("%d%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8]);
if(r==EOF) break;
for (i=0;i<9;i++)
if (a!=0)
{
if (cnt>=1)
{
if (a<0) printf(" - ");
else printf(" + ");
}
else if (cnt<1 && a<0) printf("-");
if (a<0) a=a*(-1);
if (i<7)
{
if (a==1)
printf("x^%d",9-i-1);
else
printf("%dx^%d",a,9-i-1);
}
if (i==7)
{
if (a==1)
printf("x");
else printf("%d^x",a);
}
if (i==8)
printf("%d",a[i]);
cnt++;
}
if (cnt==0) printf("0");
printf("\n");
}
return 0;
}
Here is my prograrm:
#include <stdio.h>
#include <math.h>
main()
{
int r,a[10],i,cnt;
while(1)
{
cnt =0;
r=scanf("%d%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8]);
if(r==EOF) break;
for (i=0;i<9;i++)
if (a!=0)
{
if (cnt>=1)
{
if (a<0) printf(" - ");
else printf(" + ");
}
else if (cnt<1 && a<0) printf("-");
if (a<0) a=a*(-1);
if (i<7)
{
if (a==1)
printf("x^%d",9-i-1);
else
printf("%dx^%d",a,9-i-1);
}
if (i==7)
{
if (a==1)
printf("x");
else printf("%d^x",a);
}
if (i==8)
printf("%d",a[i]);
cnt++;
}
if (cnt==0) printf("0");
printf("\n");
}
return 0;
}
do a favor and use a code tag.
about line 12(?) from bottom:
why do you have '%d^x'? maybe you meant 'x^%d'?
Ivor
about line 12(?) from bottom:
Code: Select all
else printf("%d^x",a[i]);
Ivor
392 PLZ Help
What will be the out put if all inputs are zero
i.e.
0 0 0 0 0 0 0 0 0
Thanks
i.e.
0 0 0 0 0 0 0 0 0
what is this line meaning i can't understand.....unless all terms have zero coefficients in which case the constant term should appear
Thanks
-
- Experienced poster
- Posts: 167
- Joined: Fri Oct 19, 2001 2:00 am
- Location: Saint Petersburg, Russia
Re: 392 PLZ Help
Output is just 0.rakeb wrote:What will be the out put if all inputs are zero
i.e.
0 0 0 0 0 0 0 0 0
392 - Polynomial Showdown
I got WA and WA again in 392.
Please check my output according to these input
/****INPUT*******/
0 0 0 1 22 -333 0 1 -1
-1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 -7 30 66
0 0 0 0 0 0 1 -3 0
0 0 0 0 0 -1 1 3 -1
-5 0 0 0 -243 0 0 0 -9
-0 -1 -1 -1 -1 -1 -1 -1 -1
-1999999999 -978456 0 0 0 0 56 -89 8
/****OUTPUT*****/
x^5 + 22x^4 - 333x^3 + x - 1
-x^8
0
-7x^2 + 30x + 66
x^2 - 3x
-x^3 + x^2 + 3x - 1
-5x^8 - 243x^4 - 9
-x^7 - x^6 - x^5 - x^4 - x^3 - x^2 - x - 1
-1999999999x^8 - 978456x^7 + 56x^2 - 89x + 8
Isn't that all right? Please tell me if any of them are wrong.
And please give me another creative and strange input.
Regards,
Angga888
![:(](./images/smilies/icon_frown.gif)
Please check my output according to these input
/****INPUT*******/
0 0 0 1 22 -333 0 1 -1
-1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 -7 30 66
0 0 0 0 0 0 1 -3 0
0 0 0 0 0 -1 1 3 -1
-5 0 0 0 -243 0 0 0 -9
-0 -1 -1 -1 -1 -1 -1 -1 -1
-1999999999 -978456 0 0 0 0 56 -89 8
/****OUTPUT*****/
x^5 + 22x^4 - 333x^3 + x - 1
-x^8
0
-7x^2 + 30x + 66
x^2 - 3x
-x^3 + x^2 + 3x - 1
-5x^8 - 243x^4 - 9
-x^7 - x^6 - x^5 - x^4 - x^3 - x^2 - x - 1
-1999999999x^8 - 978456x^7 + 56x^2 - 89x + 8
Isn't that all right? Please tell me if any of them are wrong.
And please give me another creative and strange input.
Regards,
Angga888
-
- Experienced poster
- Posts: 128
- Joined: Fri Nov 15, 2002 7:45 am
- Location: Kyrgyzstan
Your output is right.
Try this also.
Input:
Output:
Good luck!
Try this also.
Input:
Code: Select all
0 0 0 0 0 0 0 0 -1
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 -1 0
Code: Select all
-1
1
x
-x
-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore
It's Ok if you don't remember the tricky cases.
Since I still got WA in this problem, would you mind sending your 392.exe file to my e-mail (angga888@indosat.net.id) to check my program again ?
Thanx.
Regards,
Angga888
Since I still got WA in this problem, would you mind sending your 392.exe file to my e-mail (angga888@indosat.net.id) to check my program again ?
![:wink:](./images/smilies/icon_wink.gif)
Thanx.
Regards,
Angga888
-
- Experienced poster
- Posts: 128
- Joined: Fri Nov 15, 2002 7:45 am
- Location: Kyrgyzstan
Thx Andrey Mokhov for your 392.exe file.
After I got your exe file, I gived so many inputs to your exe file and compared the output with mine. But my output was correct for all those inputs.
Finally, I tried to submit the problem once more and I added one more line in my program (readln(input)) and I got Accepted.
Maybe, the judge test cases, can be more than 9 integers and we must calculate for the first 9 integers and ignore the rests.
I think that's why I always got WA and WA.
Regards
Angga888
After I got your exe file, I gived so many inputs to your exe file and compared the output with mine. But my output was correct for all those inputs.
Finally, I tried to submit the problem once more and I added one more line in my program (readln(input)) and I got Accepted.
![:D](./images/smilies/icon_biggrin.gif)
Maybe, the judge test cases, can be more than 9 integers and we must calculate for the first 9 integers and ignore the rests.
![:wink:](./images/smilies/icon_wink.gif)
I think that's why I always got WA and WA.
Regards
Angga888
P392 Polynomial Showdown
Do not forget to add at least one blank space at the end of each
answer line (as not specified in the rules). Otherwise, you get a WA.
answer line (as not specified in the rules). Otherwise, you get a WA.
Re: P392 Polynomial Showdown
Really?jeanmart wrote:Do not forget to add at least one blank space at the end of each
answer line (as not specified in the rules). Otherwise, you get a WA.
I didn't add any spaces but I still got Accepted.
I think the space doesn't matter.