View Code of Problem 19

#include<iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cmath>
using namespace std;
#pragma warning(disable:4996)


int main() {
	int n = 1;
	int t[100];
	while (1) {
		int tp = 0;
		scanf("%d", &n);
		if (n == 0)
			break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &t[i]);
		}
		int sum = 0;
		int max = -1000000 ;
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				sum += t[j];
				if (sum > max) {
					max = sum;
				}
			}
			sum = 0;
		}
		printf("%d", max);
	}
	return 0;
}	

Double click to view unformatted code.


Back to problem 19