码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 01-1

时间:2015-01-02 23:35:06      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:

#include <stdio.h>

int main()
{
    int i;
    int k;
    int a[100000];
    scanf("%d", &k);
    for(i = 0; i < k; i++)
    {
        scanf("%d", &a[i]);
    }
    printf("%d", MaxSubseqSum(a, k));
    return 0;
}

int MaxSubseqSum(int a[], int n)
{
    int ThisSum, MaxSum;
    int i;
    ThisSum = MaxSum = 0;
    for(i = 0; i < n; i++)
    {
        ThisSum += a[i];
        if(ThisSum > MaxSum)
            MaxSum = ThisSum;
        else if(ThisSum < 0)
            ThisSum = 0;
    }
    return MaxSum;
}

 

PAT 01-1

标签:

原文地址:http://www.cnblogs.com/happyhacking/p/4198948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!