This commit is contained in:
SOLAR D
2026-10-21 11:32:21 +02:00
parent f79eab7eac
commit a3b9b4b67e
+38 -34
View File
@@ -179,20 +179,32 @@ long nb_facons_rendre(int somme, int nb_pieces)
nb_facons_rendre(somme, nb_pieces - 1);
}
static int categorie_debit(const Transaction *t)
{
if (t->montant < -20000) {
if (t->jour % 7 == 5 || t->jour % 7 == 6)
return 1;
return 2;
}
if (t->montant < -5000)
return 3;
if (t->client % 10 == 0)
return 4;
return 5;
}
static int categorie_credit(const Transaction *t)
{
if (t->montant > 30000)
{
if (t->montant > 30000) {
if (t->client % 10 == 0 && t->jour % 7 < 5)
return 6;
return 6;
return 7;
}
}
if (t->montant > 10000)
return 8;
if (t->montant > 1000)
{
return 8;
if (t->montant > 1000) {
if (t->jour % 30 == 0)
return 9;
return 9;
return 10;
}
return 11;
@@ -202,31 +214,22 @@ static int categorie_credit(const Transaction *t)
int categorie(const Transaction *t)
{
if (t->montant < 0)
return categorie_debit(t);
return categorie_debit(t);
if (t->montant == 0)
return 0;
return 0;
return categorie_credit(t);
}
/* F10 : ajoute une ligne à la fin du rapport */
int longueur(const char *s)
void ajouter_ligne(char **fin_rapport, const char *ligne)
{
int n = 0;
while (s[n] != '\0')
n++;
return n;
}
void ajouter_ligne(char *rapport, const char *ligne)
{
int fin = longueur(rapport);
int i = 0;
while (ligne[i] != '\0') {
rapport[fin + i] = ligne[i];
i++;
while (*ligne != '\0') {
**fin_rapport = *ligne;
(*fin_rapport)++;
ligne++;
}
rapport[fin + i] = '\0';
**fin_rapport = '\0';
}
/* ------------------------------------------------------------------ */
@@ -247,6 +250,7 @@ int main(void)
{
Transaction *t = generer_transactions(NB_TRANSACTIONS);
char *rapport = malloc(1 << 20);
char *fin_rapport = rapport;
char ligne[128];
rapport[0] = '\0';
@@ -282,30 +286,30 @@ int main(void)
/* rapport */
snprintf(ligne, sizeof(ligne), "clients distincts;%d\n", nb_clients);
ajouter_ligne(rapport, ligne);
ajouter_ligne(&fin_rapport, ligne);
snprintf(ligne, sizeof(ligne), "somme des requetes;%ld\n", somme_requetes);
ajouter_ligne(rapport, ligne);
ajouter_ligne(&fin_rapport, ligne);
snprintf(ligne, sizeof(ligne), "meilleure periode;%d;%d;%ld\n", debut, fin, meilleure);
ajouter_ligne(rapport, ligne);
ajouter_ligne(&fin_rapport, ligne);
snprintf(ligne, sizeof(ligne), "paires opposees;%ld\n", nb_paires);
ajouter_ligne(rapport, ligne);
ajouter_ligne(&fin_rapport, ligne);
snprintf(ligne, sizeof(ligne), "facons de rendre %d;%ld\n", MONTANT_MONNAIE, nb_facons);
ajouter_ligne(rapport, ligne);
ajouter_ligne(&fin_rapport, ligne);
for (int c = 0; c < 12; c++) {
snprintf(ligne, sizeof(ligne), "categorie;%d;%d\n", c, categories[c]);
ajouter_ligne(rapport, ligne);
ajouter_ligne(&fin_rapport, ligne);
}
for (int c = 0; c < NB_CLIENTS; c++) {
snprintf(ligne, sizeof(ligne), "client;%d;%ld\n", c, totaux_clients[c]);
ajouter_ligne(rapport, ligne);
ajouter_ligne(&fin_rapport, ligne);
}
for (int j = 0; j < NB_JOURS; j++) {
snprintf(ligne, sizeof(ligne), "jour;%d;%ld\n", j, totaux_jours[j]);
ajouter_ligne(rapport, ligne);
ajouter_ligne(&fin_rapport, ligne);
}
for (int i = 0; i < NB_TRANSACTIONS; i += 10) {
snprintf(ligne, sizeof(ligne), "rang;%d;%d;%ld\n", i, t[i].id, t[i].montant);
ajouter_ligne(rapport, ligne);
ajouter_ligne(&fin_rapport, ligne);
}
FILE *f = fopen("rapport.txt", "w");