Code: Select all
#include <stdio.h>
typedef struct{int sum,start,stop;}maxi;
int main()
{
int liczba=0,suma=0;
maxi now,old;
int n=0,ile=0,j=0,i=0;
scanf("%d",&ile);
for (j=1;j<=ile;j++)
{
old.sum=old.start=old.stop=suma=now.sum=now.start=now.stop=0;
scanf("%d",&n);
for (i=1;i<n;i++)
{
scanf("%d",&liczba);
suma+=liczba;
if (suma>now.sum)
{
now.sum=suma;
now.stop=i+1;
}
if (suma<=0 || (i==n-1 && suma<=0))
{
suma=0;
if (old.sum<now.sum) old=now;
now.sum=0;
now.stop=0;
now.start=i+1;
}
}
printf(("The nicest part of route %d is between stops %d and %d\n"),j,old.start,old.stop);
}
return 0;
}
if (old.sum<now.sum) old=now; <-- it doesn't work

I trying to change to old.sum=now.sum ; old.start=now.start ...
but it doesn't work too

I trying change to work with only integers - not struct type.
But if (old.sum<now.sum) old=now; don't work

but if i put this old=now; before the printf the old=now is works;
ehh i'm confused

Plz help.