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

谁给看下啊?run time error

Posted by weitao at 2008-06-02 18:38:36 on Problem 2593
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int cmp(const void*e1,const void*e2)
{
    return -(*(int*)e1-*(int*)e2);
}

int main()
{	
	int n,i,j,k,sum,max,a[100000],c[100000];
	while(1)
	{
            scanf("%d",&n);
            if(n==-1)
            break;
            memset(a,0,sizeof(a));
            memset(c,0,sizeof(c));
            for(i=0;i<n;i++)
            scanf("%d",&a[i]);
            for(i=0;i<n;i++)
            {
                 
                   sum=0;
                   max=-1001;
                   for(j=i;j<n;j++)
                   {
                                   sum+=a[j];
                                   if(sum>max)
                                   max=sum;
                   }
                   if(max>0)
                   c[i]=max;
            }
            qsort(c,sizeof(c),sizeof(int),cmp);
            printf("%ld\n",c[0]+c[1]);  
    }  
		getch();
		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