View Code of Problem 19

#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while(cin>>n) {
		if(n==0) break;
		int arr[n];
		for(int i=0; i<n; i++) cin>>arr[i];
		int sum=0,max=arr[0];
		for(int i=1; i<=n; i++) {//数的个数 
			for(int j=0; j+i-1<n; j++) {//子串开始的下标 
				sum=0;
				for(int k=j; k<=j+i-1; k++) sum+=arr[k];
				if(max<sum) max=sum;				
			}
		} 
		cout<<max<<endl;
	}
}

Double click to view unformatted code.


Back to problem 19