题意:给定一组数,求最大的连续和,且输出开始与结尾
#include<iostream> #include<cstdio> using namespace std; int s[10011]; int main(){ int k,n,i,j,maxn,start,end; while(cin>>n,n){ maxn=-100; k= start = end = j = 0; for(i=0;i<n;i++){ scanf("%d",s+i); if(k+s[i]<s[i]){ k=s[i]; j = i; } else{ k+=s[i]; } if(maxn < k){ maxn = k; start = j; end = i; } } if(maxn<0) printf("0 %d %d ",s[0],s[n-1]); else printf("%d %d %d ",maxn,s[start],s[end]); } return 0; }