From dc5f6dbbd998378d3455034186bd52d4ea3236d4 Mon Sep 17 00:00:00 2001 From: abraham Date: Wed, 21 Oct 2026 11:39:59 +0200 Subject: [PATCH] EXO 4 - optimisation F3 --- banque.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/banque.c b/banque.c index 7f555e9..89ca35c 100644 --- a/banque.c +++ b/banque.c @@ -102,14 +102,14 @@ int nb_clients_distincts(const Transaction *t, int n) return nb; } -/* F3 : solde total de chaque client */ +/* F3 : solde total de chaque client en O(n + c) */ void total_par_client(const Transaction *t, int n, long *totaux) { 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++) { + totaux[t[i].client] += t[i].montant; } }