| ||||||||||
| 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 | |||||||||
大家帮忙看一下哪里有问题?是runtime error谢谢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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator