PAT 01-2

#include<stdio.h>
#include<stdlib.h> int main()
{
int k;
int *data;
int i;
int ThisSum, MaxSum, FirstNum, LastNum, tempFir, tempLas; while(scanf("%d", &k) != EOF)
{
data = (int *)malloc(k * sizeof(int));
for(i = ; i < k; i++)
{
scanf("%d", &data[i]);
} ThisSum = ;
MaxSum = ;
FirstNum = ;
LastNum = k - ;
tempFir = ;
tempLas = ; for(i = ; i < k; i++)
{
if(ThisSum >= )
{
ThisSum += data[i];
tempLas = i;
}
else
{
ThisSum = data[i];
tempFir = i;
tempLas = i;
}
if(ThisSum > MaxSum || ((LastNum == k - )&&(ThisSum == )))
{
MaxSum = ThisSum;
FirstNum = tempFir;
LastNum = tempLas;
}
}
printf("%d %d %d", MaxSum, data[FirstNum], data[LastNum]);
}
}
上一篇:android studio 导入第三方库的记录


下一篇:Lua自己实现string.split功能