求陣列中和最大的子陣列與始末下標

2021-08-27 13:39:48 字數 1266 閱讀 2313

using system;

using system.collections.generic;

using system.linq;

using system.text;

namespace maxsum

; myarray = new

int ;

//myarray = new int ;

//myarray = new int ;

//myarray = new int ;

getmaxsum(myarray, myarray.length);

}///

///獲取連續子陣列的最大和

//////

目標陣列

///陣列的長度

private

static

void getmaxsum(int array, int length)

else

if (sum < temp) //

如果此時 sum < temp;則表示此時的子陣列和大於之前的子陣列和}//

顯示最終的結果(從陣列的第n個元素到m個元素之和最大)

displayresult(array, sum, startindex, endindex);

}///

///顯示最終的結果

//////

目標陣列

///最大子陣列之和

///最大子陣列的起始位置(按陣列下標從0開始計數)

///最大子陣列的終止位置(按陣列下標從0開始計數)

private

static

void displayresult(int array, int maxsum, int startindex, int endindex)

string expression = string.empty;

for (int i = startindex; i <= endindex; i++)

)", array[i].tostring()) + "

+ ";

}else

} console.writeline("

\n");

console.writeline("

the final result is : sum(,) = =

", startindex, endindex, expression.trimend(new

char ), maxsum);}}

}

求陣列中和最大的子陣列與始末下標

using system using system.collections.generic using system.linq using system.text namespace maxsum myarray new int myarray new int myarray new int mya...

求陣列中和最大的子陣列與始末下標

using system using system.collections.generic using system.linq using system.text namespace maxsum myarray new int myarray new int myarray new int mya...

求陣列中和最大的子陣列

題目一 輸入乙個整形陣列,陣列裡有正數也有負數。陣列中連續的乙個或多個整數組成乙個子陣列,每 個子陣列都有乙個和。求所有子陣列的和的最大值。要求時間複雜度為o n cpp view plain copy include stdio.h include conio.h 求一維陣列的最大連續子陣列元素之...