forked from menault/2026_TD3_DEV51_Qualite_Algo
F10
This commit is contained in:
@@ -179,20 +179,32 @@ long nb_facons_rendre(int somme, int nb_pieces)
|
|||||||
nb_facons_rendre(somme, nb_pieces - 1);
|
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)
|
static int categorie_credit(const Transaction *t)
|
||||||
{
|
{
|
||||||
if (t->montant > 30000)
|
if (t->montant > 30000) {
|
||||||
{
|
|
||||||
if (t->client % 10 == 0 && t->jour % 7 < 5)
|
if (t->client % 10 == 0 && t->jour % 7 < 5)
|
||||||
return 6;
|
return 6;
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
if (t->montant > 10000)
|
if (t->montant > 10000)
|
||||||
return 8;
|
return 8;
|
||||||
if (t->montant > 1000)
|
if (t->montant > 1000) {
|
||||||
{
|
|
||||||
if (t->jour % 30 == 0)
|
if (t->jour % 30 == 0)
|
||||||
return 9;
|
return 9;
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
return 11;
|
return 11;
|
||||||
@@ -202,31 +214,22 @@ static int categorie_credit(const Transaction *t)
|
|||||||
int categorie(const Transaction *t)
|
int categorie(const Transaction *t)
|
||||||
{
|
{
|
||||||
if (t->montant < 0)
|
if (t->montant < 0)
|
||||||
return categorie_debit(t);
|
return categorie_debit(t);
|
||||||
if (t->montant == 0)
|
if (t->montant == 0)
|
||||||
return 0;
|
return 0;
|
||||||
return categorie_credit(t);
|
return categorie_credit(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* F10 : ajoute une ligne à la fin du rapport */
|
/* 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 (*ligne != '\0') {
|
||||||
while (s[n] != '\0')
|
**fin_rapport = *ligne;
|
||||||
n++;
|
(*fin_rapport)++;
|
||||||
return n;
|
ligne++;
|
||||||
}
|
|
||||||
|
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
rapport[fin + i] = '\0';
|
**fin_rapport = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------ */
|
||||||
@@ -247,6 +250,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
Transaction *t = generer_transactions(NB_TRANSACTIONS);
|
Transaction *t = generer_transactions(NB_TRANSACTIONS);
|
||||||
char *rapport = malloc(1 << 20);
|
char *rapport = malloc(1 << 20);
|
||||||
|
char *fin_rapport = rapport;
|
||||||
char ligne[128];
|
char ligne[128];
|
||||||
rapport[0] = '\0';
|
rapport[0] = '\0';
|
||||||
|
|
||||||
@@ -282,30 +286,30 @@ int main(void)
|
|||||||
|
|
||||||
/* rapport */
|
/* rapport */
|
||||||
snprintf(ligne, sizeof(ligne), "clients distincts;%d\n", nb_clients);
|
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);
|
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);
|
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);
|
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);
|
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++) {
|
for (int c = 0; c < 12; c++) {
|
||||||
snprintf(ligne, sizeof(ligne), "categorie;%d;%d\n", c, categories[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++) {
|
for (int c = 0; c < NB_CLIENTS; c++) {
|
||||||
snprintf(ligne, sizeof(ligne), "client;%d;%ld\n", c, totaux_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++) {
|
for (int j = 0; j < NB_JOURS; j++) {
|
||||||
snprintf(ligne, sizeof(ligne), "jour;%d;%ld\n", j, totaux_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) {
|
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);
|
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");
|
FILE *f = fopen("rapport.txt", "w");
|
||||||
|
|||||||
Reference in New Issue
Block a user