/*********************************
* 日期:2012-6-30
* 作者:SJF0115
* 题号: 九度1011
* 题目:最大连续子序列
* 结果:AC
* 题意:
* 总结:
**********************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int K;
int sequence[10001];
//输入重定向,输入数据将从in.txt文件中读取
//freopen("C:\\Users\\SJF\\Desktop\\in.txt","r",stdin);
while(scanf("%d",&K)!=EOF)
{
int i,j;
if(K == 0){
break;
}
for(i = 0;i<K;i++){
scanf("%d",&sequence[i]);
}
int currentMax = 0,Max = -32768;
int start = 0,end = 0;
for(i = 0,j = 0;j < K; j++){
currentMax += sequence[j];
if(currentMax < 0){
currentMax = 0;
i = j+1;
}
else if(currentMax > Max){
Max = currentMax;
start = i;
end = j;
}
}
if(start == end && end == 0 && Max < 0){
printf("%d %d %d\n",0,sequence[0],sequence[K-1]);
}
else{
printf("%d %d %d\n",Max,sequence[start],sequence[end]);
}
}
return 0;
}
九度1011 最大连续子序列
最新推荐文章于 2022-02-25 19:38:17 发布