forked from menault/2026_TD3_DEV51_Qualite_Algo
F5
This commit is contained in:
@@ -128,18 +128,21 @@ void total_par_jour(const Transaction *t, int n, long *totaux)
|
|||||||
long meilleure_periode(const long *totaux, int nb_jours, int *debut, int *fin)
|
long meilleure_periode(const long *totaux, int nb_jours, int *debut, int *fin)
|
||||||
{
|
{
|
||||||
long meilleur = totaux[0];
|
long meilleur = totaux[0];
|
||||||
|
long somme_courante = totaux[0];
|
||||||
|
int debut_courant = 0;
|
||||||
*debut = 0;
|
*debut = 0;
|
||||||
*fin = 0;
|
*fin = 0;
|
||||||
for (int i = 0; i < nb_jours; i++) {
|
for (int j = 1; j < nb_jours; j++) {
|
||||||
for (int j = i; j < nb_jours; j++) {
|
if (somme_courante < 0) {
|
||||||
long somme = 0;
|
somme_courante = totaux[j];
|
||||||
for (int k = i; k <= j; k++)
|
debut_courant = j;
|
||||||
somme += totaux[k];
|
} else {
|
||||||
if (somme > meilleur) {
|
somme_courante += totaux[j];
|
||||||
meilleur = somme;
|
}
|
||||||
*debut = i;
|
if (somme_courante > meilleur) {
|
||||||
*fin = j;
|
meilleur = somme_courante;
|
||||||
}
|
*debut = debut_courant;
|
||||||
|
*fin = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return meilleur;
|
return meilleur;
|
||||||
|
|||||||
Reference in New Issue
Block a user