杭電oj-1003--Max sum

一開始我是分開考慮開始的下標(biāo)和結(jié)束的下標(biāo)的。
直到看見某位大佬的代碼
原諒我太菜!!!

#include <stdio.h>

int main(void)
{
    /*********膜拜大佬的代碼******/
    int row, n, i, j, starti, maxi, tempi, max, temp;
    int a[100000];
    scanf("%d", &row);
    for (i = 0; i < row; i++)
    {
        //初始化
        int a[100000] = { 0 };
        max    = -1001;
        temp   = 0;
        tempi  = 1;
        scanf("%d", &n);
        for (j = 1; j <= n; j++)
        {
            //Input
            scanf("%d", &a[j]);

            temp += a[j];
            if (temp > max)
            {
                max    = temp;
                starti = tempi;
                maxi = j;
            }
            if (temp < 0)
            {
                temp  = 0;
                tempi = j + 1;
            }
        }    

        //Output
        printf("Case %d:\n", i+1);
        printf("%d %d %d\n", max, starti, maxi);
        if (i != row - 1)
            printf("\n");
    }
    return 0;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容