View Code of Problem 19

#include <iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

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

	/*
		用选择法对10个整数从小到大排序
	*/

	int n;
	while( scanf("%d" , &n)!=EOF ) {
		if( n <= 0)
			break;
		int a[1000];
		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;
}

Double click to view unformatted code.


Back to problem 19