结对开发 我的队友是王春帆20132902博客园地址http://www.cnblogs.com/-beauTiFul/
/* 设计思路: 输入数组 -3 4 2 -7 6 1 a[0]=sz[0];-3 a[1]=max(a[0]+sz[1],sz[1]);4 a[2]=max(a[1]+sz[2],sz[2]);6 a[3]=max(a[2]+sz[3],sz[3]);-1 a[4]=max(a[3]+sz[4],sz[4]);6 a[5]=max(a[4]+sz[5],sz[5]);7 max(a[0],a[1]...a[n]) */ #include<iostream> #include <algorithm> #include<cstdio> #include<vector> using namespace std; int main() { int i, szgs, maxsum; int sz[100],a[100];//最大数组 cout << "请输入数组元素个数:"; cin >> szgs; cout << "请输入数组元素:"; for (i = 0; i < szgs; i++) { cin>>sz[i]; } a[0]=maxsum = sz[0]; if (szgs>0) { for (i = 1; i < szgs; i++) { a[i] = max(a[i - 1] + sz[i], sz[i]); maxsum = max(maxsum, a[i]); } } cout << "最大子数组的和为:" << maxsum << endl; }