----------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------
方法一:
- 暴力求解法,即使用三重循环进行遍历,其时间复杂度为0(N^3)
代码如下:
/*
--------------------------------------------------
function: to calculate the maximum sequence sum of
the given sequence; if all are negative,
to make the sum equal 0
example:
input: 6
-7 6 -3 4 -2 1
output: 7
author: sunny
date: 2017.03.05
platform: ubuntu 14.04LTS
complier: gcc
-------------------------------------------------
*/
#include <stdio.h>
int GetNumCount(void); //to get the count of the number
void GetSeqNum(int [], int);
void ClearIOBuffer(void); //to clear the input buffer
int GetMaxSeqSum(int [], int);
int main(void)
{
int numCount, MaxSeqSum;
int numArray[numCount];
numCount = GetNumCount();
GetSeqNum(numArray, numCount);
MaxSeqSum = GetMaxSeqSum(numArray, numCount);
printf("MaxSeqSum = %d\n", MaxSeqSum);
return 0;
}
int GetNumCount(void) {
int count;
printf("Enter the count of number:");
scanf("%d", &count);
ClearIOBuffer();
return count;
}
void ClearIOBuffer(void) {
while(getchar() !=