Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

!!!!!!!能不能帮我看看那里错了

Posted by mmjiajia at 2008-06-21 12:00:04 on Problem 1555
#include <cstdio>
#include <cmath>
int main()
{
    int a[9];
    while(scanf("%d %d %d %d %d %d %d %d %d",a+8,a+7,a+6,a+5,a+4,a+3,a+2,a+1,a)!=EOF)
    {
        bool flag = false;   
        for(int i=8;i>=0;i--)
        {    
            if(a[i]) 
            {
                if(flag == false)
                {
                    if(fabs(a[i])==1)
                    {
                       if(a[i]==-1&&i>1)
                          printf("-x^%d",i);  
                       else if(a[i]==-1 && i==1)
                           printf("-x");
                       else if(a[i]==-1 && i==0)
                           printf("-1");                  
                       else
                       {   
                           if(i>=2) printf("x^%d",i);
                           else if(i==1) printf("x");
                           else if(i==0) printf("%d",a[0]);
                       }
                    }
                    else
                    {  
                        printf("%d",a[i]);        
                        if(i>1) printf("x^%d",i);
                        else if(i==1) printf("x");
                        else if(i==0) printf("%d",a[0]);
                    }
                    flag = true;
                }
                else
                {
                    if(i>=2)
                    {   
                        if(a[i]>0) printf(" + ");
                        else {printf(" - "); a[i]=-a[i];}
                        if(a[i]!=1) printf("%d",a[i]);
                        printf("x^%d",i);
                    }
                    else
                    {
                        if(i==1)
                        {
                            if(a[i]>0) printf(" + ");
                            else {printf(" - "); a[i]=-a[i];}
                            if(a[i]!=1) printf("%d",a[i]);
                            printf("x",a[i]);      
                        }
                        else if(i==0)
                        {
                            if(a[i]>0) printf(" + ");
                            else {printf(" - "); a[i]=-a[i];}
                            printf("%d",a[i]);      
                        }    
                    }
                    flag = true;         
                }         
            }
        }
        if(!flag) printf("0");
        puts("");      
    }    
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator