标签:style class color int strong rgb
1题目:
见代码。
#include<stdio.h> int main(){ int n, a[10001], left, beforeleft, right, i, max, sum; while(scanf("%d", &n) && n){ for(i = 0; i < n; i ++){ scanf("%d", &a[i]); } max = a[0]; sum = 0; left = right = beforeleft = 0; for(i = 0; i < n; i ++){ sum += a[i]; if(sum > max){ //只有满足这个条件才可以给left和right赋新值 left = beforeleft; //用beforeleft来记录原先的最左边的值 right = i; max = sum; } if(sum < 0){ sum = 0; beforeleft = i + 1; } } if(max < 0){ max = 0; left = 0; right = n - 1; } printf("%d %d %d\n", max, a[left], a[right]); } return 0; }
标签:style class color int strong rgb
原文地址:http://www.cnblogs.com/xiaoyeye/p/3710557.html