View Code of Problem 19

#include "stdio.h"
void main()
{	
	int a[100];
	int n,j,i;
	int max,sum;
	for(i=0;scanf("%d",&n)!=0;i++)
	{
	//	if(n==0)
		//	break;

		for(j=0;j<n;j++)
		{
			scanf("%d",&a[j]);
		}
		sum=0;
		max=-1000;
		for(j=0;j<n;j++)
		{
			if (sum>0)					//大于0往后加
				sum=sum+a[j];
			else 
				sum=a[j];				//小于0给当前位置数字
			if(sum>max)
				max=sum;				//整个过程中最大值
		}
		printf("%d\n",max);
	}
}

Double click to view unformatted code.


Back to problem 19