错误提示: 并列和对应相同i但是不同j,即尾是0
但是我已经试过去掉尾部或者不去掉尾部,都不行
以下是去掉尾部的代码,请看看到底是什么问题
#include<stdio.h>
#include<stdbool.h>
int a[10000], b[10000] = { 0 }, CountMax = 0;
bool flag0 = 1;
int MaxSubseqSum(int* a, int k)
{
int SumTemp = 0, MaxSum = 0, Count = 0, i;
for (i = 0; i < k; i++)
{
if (a[i] == 0) flag0 = 0;
SumTemp += a[i];
Count++;
if (SumTemp > MaxSum) {
MaxSum = SumTemp;
b[Count - 1] = a[i];
CountMax = Count;
}
else if (SumTemp <= 0)
{
SumTemp = 0;
Count = 0;
}
}
return MaxSum;
}
int main(void)
{
int k, i, Ans;
bool flag = 1;
scanf("%d", &k);
for (i = 0; i < k; i++)
{
scanf("%d", &a[i]);
}
Ans = MaxSubseqSum(a, k);
if (CountMax == 0 && flag0 == 1) printf("0 %d %d", a[0], a[k - 1]);
else
{
if (CountMax == 0 && flag0 == 0) printf("0 0 0");
else
printf("%d %d %d", Ans, b[0], b[CountMax - 1]);
}
return 0;
}