Compare commits

..

5 Commits

Author SHA1 Message Date
Valentin Loison d6299b2c28 Merge branch 'main' of https://grond.iut-fbleau.fr/solar/2026_TD3_DEV51_Qualite_Algo 2026-10-21 11:10:42 +02:00
Valentin Loison 914e03b290 fixes F2 2026-10-21 11:08:30 +02:00
SOLAR D ff27c1c013 F1 2026-10-21 11:04:07 +02:00
SOLAR D c54a416069 F4 2026-10-21 10:48:28 +02:00
SOLAR D 5f05c1abfe F3 2026-10-21 10:38:30 +02:00
+28 -29
View File
@@ -71,36 +71,34 @@ Transaction *generer_transactions(int n)
/* ------------------------------------------------------------------ */
/* F1 : trie les transactions par montant croissant, puis par id */
static int comparer_transactions(const void *a, const void *b)
{
const Transaction *x = a, *y = b;
if (x->montant != y->montant)
return (x->montant > y->montant) - (x->montant < y->montant);
return (x->id > y->id) - (x->id < y->id);
}
void trier_par_montant(Transaction *t, int n)
{
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1 - i; j++) {
if (t[j].montant > t[j + 1].montant ||
(t[j].montant == t[j + 1].montant && t[j].id > t[j + 1].id)) {
Transaction tmp = t[j];
t[j] = t[j + 1];
t[j + 1] = tmp;
}
}
}
qsort(t, n, sizeof *t, comparer_transactions);
}
/* F2 : nombre de clients ayant au moins une transaction */
int nb_clients_distincts(const Transaction *t, int n)
{
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)
nb++;
int nbr_clients = 0;
int *deja_vu = (int*) calloc(NB_CLIENTS,sizeof(int));
for (int i = 0 ; i < n ; i++){
if (deja_vu[t[i].client] == 0){
deja_vu[t[i].client] = 1;
nbr_clients +=1;
}
}
return nb;
free(deja_vu);
return nbr_clients;
}
/* F3 : solde total de chaque client */
@@ -108,20 +106,21 @@ 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;
}
/* 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++) {
int jour = t[i].jour;
if (jour >= 0 && jour < NB_JOURS)
totaux[jour] += t[i].montant;
}
}