392 - Polynomial Showdown PE -- plz help

All about problems in Volume III. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

392 - Polynomial Showdown PE -- plz help

Postby Rushow » Sun Aug 17, 2008 5:34 pm

I have tried many I/O,but for all I got the correct ans
but still PE . can anyone help me? Here's my code
Code: Select all
/* p392 */

/* Polynomial Showdown */

#include<stdio.h>

int main(void)
{
   int pol[12], i, j, flag, flag_1st, sum;

   //freopen("input.in", "r", stdin);

   
   while(scanf("%d%d%d%d%d%d%d%d%d", &pol[0], &pol[1], &pol[2], &pol[3], &pol[4], &pol[5], &pol[6], &pol[7], &pol[8]) == 9 )
   {
         
      flag = 0; flag_1st = 0; sum = 0;
      
      for( i = 0, j = 8; i < 9; i++, j--)
      {
         if(pol[i] < 0)
            sum = sum + (pol[i] * (-1));
         else
            sum = sum + pol[i];
         if(pol[i] != 0)
         {
            flag_1st++;
            if( pol[i] < 0)
            {
               printf("-");
               if( flag == 1 )
                  printf(" ");
   
               pol[i] = pol[i] * -1;
               flag_1st++;
            }
            else if( pol[i] > 0 )
            {
               if(flag_1st != 1)
               {
                  printf("+ ");
               }
            }
            
            
            flag_1st++;   
            if( pol[i] == 1)
            {
               if( i == 7 )
                  printf("x ");
               else if( i == 8 )
                  printf("1");
               else
                  printf("x^%d ", j);
               
               flag = 1;
            }
            else if( pol[i] > 1 )
            {
               if( i == 7 )
                  printf("%dx ", pol[i]);
               else if( i == 8 )
                  printf("%d", pol[i]);
               else
                  printf("%dx^%d ", pol[i], j);
   
               flag = 1;
            }
   
   
            
         }
         if(i == 8 && sum == 0)
            printf("0");
   
         
      }//end for
      
      printf("\n");
   }//end while
   
         
   return 0;
}//end main
Rushow
New poster
 
Posts: 14
Joined: Sat Oct 14, 2006 4:09 pm
Location: Dhaka,Bangladesh

Re: 392 - Polynomial Showdown PE -- plz help

Postby kbr_iut » Mon Aug 18, 2008 2:24 am

warning::::dont open a new thread while there r lot of threads.

for this input
Code: Select all
0 0 0 0 0 0 1 0 0

ur program gives
Code: Select all
x^2_

here I replace space character with '_';
so ur program gives an extra space .
think about that.
hople it helps.
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................
User avatar
kbr_iut
Experienced poster
 
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH

Re: 392 - Polynomial Showdown PE -- plz help

Postby Rushow » Mon Aug 18, 2008 6:11 am

thnx I got it
Get AC :D :D
Rushow
New poster
 
Posts: 14
Joined: Sat Oct 14, 2006 4:09 pm
Location: Dhaka,Bangladesh

Re: 392 - Polynomial Showdown PE -- plz help

Postby shantanu18 » Mon Jun 20, 2011 11:00 pm

I found the bug of my code. When all input is 0 then output is 0. I missed that. Now AC!
Code: Select all
Got AC
shantanu18
New poster
 
Posts: 22
Joined: Tue Jul 20, 2010 9:55 pm


Return to Volume III

Who is online

Users browsing this forum: No registered users and 1 guest