forked from menault/2026_TD1_DEV51_Qualite_Algo
première opti
This commit is contained in:
+10
-8
@@ -22,7 +22,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NB_MOTS_TEXTE 250000
|
||||
#define NB_MOTS_TEXTE 2500000
|
||||
#define NB_MOTS_VOCAB 7000
|
||||
#define TAILLE_MOT 32
|
||||
#define MAX_MOTS_UNIQUES 20000
|
||||
@@ -32,6 +32,7 @@
|
||||
/* Générateur pseudo-aléatoire (identique sur toutes les machines) */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
|
||||
static unsigned long etat_alea = GRAINE;
|
||||
|
||||
unsigned long alea(void)
|
||||
@@ -224,6 +225,7 @@ void normaliser_ligne(char *ligne)
|
||||
typedef struct {
|
||||
char mot[TAILLE_MOT];
|
||||
int occurrences;
|
||||
int longueur_mot;
|
||||
} Entree;
|
||||
|
||||
int est_mot_vide(const char *mot)
|
||||
@@ -260,7 +262,7 @@ int chercher_mot(Entree *table, const char *mot, unsigned long *case_libre)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void compter_mot(Entree *table, int *nb_entrees, const char *mot)
|
||||
void compter_mot(Entree *table, int *nb_entrees, const char *mot, int longueur_mot)
|
||||
{
|
||||
/* Réinitialisation possible pour un nouveau comptage. */
|
||||
if (*nb_entrees == 0)
|
||||
@@ -277,6 +279,7 @@ void compter_mot(Entree *table, int *nb_entrees, const char *mot)
|
||||
}
|
||||
copier(table[*nb_entrees].mot, mot);
|
||||
table[*nb_entrees].occurrences = 1;
|
||||
table[*nb_entrees].longueur_mot = longueur_mot;
|
||||
index_mots[position] = *nb_entrees + 1;
|
||||
(*nb_entrees)++;
|
||||
}
|
||||
@@ -301,7 +304,7 @@ void compter_mots_ligne(Entree *table, int *nb_entrees, const char *ligne,
|
||||
if (k > 0) {
|
||||
(*nb_mots_total)++;
|
||||
if (!est_mot_vide(mot))
|
||||
compter_mot(table, nb_entrees, mot);
|
||||
compter_mot(table, nb_entrees, mot, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -358,16 +361,15 @@ double longueur_moyenne(const Entree *table, int n)
|
||||
{
|
||||
long total = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
total += longueur(table[i].mot);
|
||||
total += table[i].longueur_mot;
|
||||
return (double)total / n;
|
||||
}
|
||||
|
||||
double ecart_type_longueur(const Entree *table, int n)
|
||||
double ecart_type_longueur(const Entree *table, int n, double moyenne)
|
||||
{
|
||||
double somme = 0.0;
|
||||
double moyenne = longueur_moyenne(table, n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
double ecart = longueur(table[i].mot) - moyenne;
|
||||
double ecart = table[i].longueur_mot - moyenne;
|
||||
somme += ecart * ecart;
|
||||
}
|
||||
return somme / n; /* variance ; la racine est prise dans main */
|
||||
@@ -474,7 +476,7 @@ int main(void)
|
||||
trier_entrees(table, nb_entrees);
|
||||
|
||||
double moyenne = longueur_moyenne(table, nb_entrees);
|
||||
double ecart_type = racine(ecart_type_longueur(table, nb_entrees));
|
||||
double ecart_type = racine(ecart_type_longueur(table, nb_entrees, moyenne));
|
||||
|
||||
char trigramme[4];
|
||||
int occ_trigramme;
|
||||
|
||||
Reference in New Issue
Block a user