| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
谁给看下啊?run time error#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator