From 6c8b915aa60f17446a9497fa20f87af0a80bf4ba Mon Sep 17 00:00:00 2001 From: Ryad MEHIRI Date: Wed, 21 Oct 2026 10:56:29 +0200 Subject: [PATCH] =?UTF-8?q?F4=20:=20solde=20par=20jour=20en=20un=20seul=20?= =?UTF-8?q?parcours=20(O(n=20=C3=97=20J)=20=E2=86=92=20O(n=20+=20J))?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Même correction que F3 : au lieu de reparcourir les 30 000 transactions pour chacun des 1 000 jours (30 millions de tests), chaque montant est ajouté directement au total de son jour. Temps (-O2) : 0,087 s → 0,073 s. Empreinte inchangée (ff68d260a7a58441). Co-Authored-By: Claude Opus 5.5 --- banque.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/banque.c b/banque.c index 6a684a9..6e833e6 100644 --- a/banque.c +++ b/banque.c @@ -116,12 +116,10 @@ void total_par_client(const Transaction *t, int n, long *totaux) /* F4 : solde total de chaque jour */ void total_par_jour(const Transaction *t, int n, long *totaux) { - for (int j = 0; j < NB_JOURS; j++) { + for (int j = 0; j < NB_JOURS; j++) totaux[j] = 0; - for (int i = 0; i < n; i++) - if (t[i].jour == j) - totaux[j] += t[i].montant; - } + for (int i = 0; i < n; i++) /* un seul parcours, comme pour F3 */ + totaux[t[i].jour] += t[i].montant; } /* F5 : période de jours consécutifs dont la somme des soldes est maximale */