int _tmain(int argc, _TCHAR* argv[])
{
int sum=0;
int left=0;
int right=0;
int max=0;
int A[]={13,-3,-25,20,-3,-16,-23,18,20,-7,12,-5,-22};
//不包含数组里全是负数的情况
for(int i=0;i<sizeof(A)/sizeof(A[0]);++i)
{
sum+=A[i];
if(sum>max)
{
max=sum;
right=i;
}
else if(sum<0)
{
sum=0;
left=i+1;
}
else
continue;
}
if(left>right)
for(left=right;max-A[left]>=0;--left);
printf("最大子数组从第%d个元素开始,到第%d个元素结束\n",left+1,right+1);
printf("其和为:%d\n",max);
system("pause");
return 0;
}