#include<iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <cmath> using namespace std; #pragma warning(disable:4996) int main() { int n = 1; int t[100]; while (1) { int tp = 0; scanf("%d", &n); if (n == 0) break; for (int i = 0; i < n; i++) { scanf("%d", &t[i]); } int j; for(j = 0; j < n; j++) { if (t[j] > 0) { tp = j; break; } } int sum = 0; int max = t[tp]; if (j == n) { for (int i = 0; i < n; i++) { if (t[i] > max) { max = t[i]; } } } else { for (int i = tp; i < n; i++) { sum += t[i]; if (sum > max) { max = sum; } } } printf("%d\n", max); } return 0; } |
Double click to view unformatted code.