From 6eb65d3903e385d7b1cf7a266398cf4e3874f21f Mon Sep 17 00:00:00 2001 From: bounnilo Date: Mon, 26 Oct 2026 15:09:01 +0100 Subject: [PATCH] opti n2 --- banque.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/banque.c b/banque.c index 7e921af..907f275 100644 --- a/banque.c +++ b/banque.c @@ -96,21 +96,22 @@ void trier_par_montant(Transaction *t, int n) qsort(t, n, sizeof(Transaction), comparer_transactions); } +/* F2 : nombre de clients ayant au moins une transaction */ /* F2 : nombre de clients ayant au moins une transaction */ int nb_clients_distincts(const Transaction *t, int n) { int nb = 0; + int vus[NB_CLIENTS] = {0}; + for (int i = 0; i < n; i++) { - int deja_vu = 0; - for (int j = 0; j < i; j++) { - if (t[j].client == t[i].client) { - deja_vu = 1; - break; - } - } - if (!deja_vu) + int client = t[i].client; + + if (!vus[client]) { + vus[client] = 1; nb++; + } } + return nb; }