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

大家帮忙看一下哪里有问题?是runtime error谢谢

Posted by byr at 2006-04-14 20:34:56 on Problem 2593
const short  inf = -2001;

short * a;
int max,s,i,n,* b,* c;
int main()
{
    scanf("%d",&n);
    
    while(n>0)
    {
        a=new short[n];
        b=new int[n];
        c=new int[n];  
         for(i=0; i<=n-1; i++)
            scanf("%d",&a[i]); 
                  
        max = inf;
        s = 0;
        for(i=0; i<=n-1; i++)
        {
            if(s>=0)
                s+=a[i];   
            else
                s = a[i];
            if(s>max)
                max = s;    
            b[i] = max; 
        }
        
        max = inf;
        s = 0;
        for(i=n-1; i>=0; i--)
        {
            if(s>=0)
                s+=a[i]; 
            else
                s = a[i];  
       		if(s>max)
                max = s;  
            c[i] = max;    
        }   
        max = inf;
        for(i=0; i<=n-2; i++)
            if(b[i]+c[i+1]>max)
            max = b[i]+c[i+1];    
        printf("%d\n",max);
        
        delete [] a;
        delete [] b;
        delete [] c;
        scanf("%d",&n);               
    } 
    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