标签:
1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 5 int main() 6 { 7 int c, input, maxSum, frontPos, tempFrontPos, tailPos, tempSum; 8 int ct = 1; 9 scanf("%d", &c); 10 while(c--) 11 { 12 tempSum = 0; 13 maxSum = -1000000000; 14 tempFrontPos = frontPos = tailPos = 0; 15 int n; 16 scanf("%d", &n); 17 for(int i = 0; i < n; ++i) 18 { 19 scanf("%d", &input); 20 tempSum += input; 21 if(tempSum > maxSum) 22 { 23 maxSum = tempSum; 24 tailPos = i; 25 frontPos = tempFrontPos; 26 } 27 if(tempSum < 0 && (i != n - 1)) //i != n - 1 保证 frontPos 不会指到一个不存在的位置 28 { 29 tempSum = 0; 30 tempFrontPos = i + 1; 31 } 32 } 33 printf("Case %d:\n", ct++); 34 printf("%d %d %d\n", maxSum, frontPos+1, tailPos+1); 35 if(c != 0) printf("\n"); 36 } 37 return 0; 38 }
标签:
原文地址:http://www.cnblogs.com/Artprog/p/4851782.html