From b40294698ca7c9e830c9e416223c161d782f73fa Mon Sep 17 00:00:00 2001 From: Ryad MEHIRI Date: Wed, 21 Oct 2026 10:56:11 +0200 Subject: [PATCH] =?UTF-8?q?F3=20:=20solde=20par=20client=20en=20un=20seul?= =?UTF-8?q?=20parcours=20(O(n=20=C3=97=20C)=20=E2=86=92=20O(n=20+=20C))?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pour chacun des 2 000 clients, on reparcourait les 30 000 transactions (60 millions de tests). On met les totaux à zéro, puis chaque montant est ajouté directement au total de son client. Les montants de chaque client sont additionnés dans le même ordre : les totaux sont identiques. Temps (-O2) : 0,097 s → 0,087 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 3b030e6..6a684a9 100644 --- a/banque.c +++ b/banque.c @@ -107,12 +107,10 @@ int nb_clients_distincts(const Transaction *t, int n) /* F3 : solde total de chaque client */ void total_par_client(const Transaction *t, int n, long *totaux) { - for (int c = 0; c < NB_CLIENTS; c++) { + for (int c = 0; c < NB_CLIENTS; c++) totaux[c] = 0; - for (int i = 0; i < n; i++) - if (t[i].client == c) - totaux[c] += t[i].montant; - } + for (int i = 0; i < n; i++) /* un seul parcours : chaque montant va */ + totaux[t[i].client] += t[i].montant; /* directement au total de son client */ } /* F4 : solde total de chaque jour */