Optimiser F2 avec un tableau de clients rencontrés

This commit is contained in:
rabot
2026-10-21 11:11:56 +02:00
parent b6352e063b
commit 2b34b35f2b
3 changed files with 30 additions and 8 deletions
+4 -8
View File
@@ -116,17 +116,13 @@ void trier_par_montant(Transaction *t, int n)
/* F2 : nombre de clients ayant au moins une transaction */
int nb_clients_distincts(const Transaction *t, int n)
{
unsigned char vus[NB_CLIENTS] = {0};
int nb = 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)
if (!vus[t[i].client]) {
vus[t[i].client] = 1;
nb++;
}
}
return nb;
}