题目地址:
http://acm.jlu.edu.cn/joj/showproblem.php?pid=1995
我的代码:
#include <iostream>
using namespace std;
int main()
{
int n;
while (cin >> n && n != -1)
{
int a[n+1];
for (int i = 0;i <= n;i ++)
a[i] = 0;
for (int k = 1;k <= n;k ++)
cin >> a[k];
int sum = 0;
int b = 0;
for (int i = 1;i <= n;i ++)
{
if (b > 0) b += a[i];
else b = a[i];
if (b > sum) sum = b;
}
cout << sum << endl;
}
}
一直wa,郁闷