View Code of Problem 19

// b.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>


int main(int argc, char* argv[])
{

	int n;
	while( scanf("%d" , &n)!=EOF ) {
		if( n <= 0)
			break;
		int a[10000];
		for(int k = 0 ; k < n ; k++)
			scanf("%d" , &a[k]);
		int max = a[0];
		for(int i = 0 ; i < n ; i++) {
			int sum = 0;
			for(int j = i + 1 ; j < n ; j++) {
				sum += a[j];
				if(max < sum)
					max = sum;
			}
		}
		if(max < a[n - 1] )
			max=  a[ n - 1];
		printf("%d\n" , max);

	}

	return 0;
}

/*
Main.cc:4:20: fatal error: stdafx.h: No such file or directory
 #include "stdafx.h"
                    ^
compilation terminated.
*/

Double click to view unformatted code.


Back to problem 19