1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| #include <stdio.h>
#include <stdlib.h>
struct data
{
int Indice;
int Combi[5];
int N[4];
};
struct node
{
struct data data;
struct node *psuiv;
};
struct liste
{
struct node *pTete;
struct node *pQueue;
};
static void Filtrage (void)
{
FILE *In = fopen ("resultats_num.txt", "r");
if (In != NULL)
{
FILE *Out = fopen ("resultats_num_treated.txt", "w");
if (Out != NULL)
{
int car;
printf ("Treating File Num...\n\n");
while ((car = fgetc (In)) != EOF)
{
if ((car != '[') && (car != ']') && (car != ','))
{
putc (car, Out);
}
}
fclose (Out);
}
fclose (In);
}
}
static void add (struct liste *p_liste, struct data const *p_data)
{
struct node *pNouveau = malloc (sizeof *pNouveau);
if (pNouveau != NULL)
{
pNouveau->data = *p_data;
pNouveau->psuiv = NULL;
if (p_liste->pTete == NULL)
{
/* Premier maillon = Premiere Ligne */
p_liste->pTete = pNouveau;
}
else
{
p_liste->pQueue->psuiv = pNouveau;
}
p_liste->pQueue = pNouveau;
}
}
static void LoadCombi (struct liste *p_liste)
{
FILE *Out = fopen ("resultats_num_treated.txt", "r");
if (Out != NULL)
{
struct data data;
printf ("Creation liste Chainee...\n\n");
{
int i = 0;
while (fscanf (Out, " %d %d %d %d %d\n ", &data.Combi[0],
&data.Combi[1], &data.Combi[2],
&data.Combi[3], &data.Combi[4]) == 5)
{
data.Indice = i;
int j = 0;
for (j=0; j<4; j++) {
data.N[j]=0;
}
i++;
add (p_liste, &data);
}
}
fclose (Out);
}
}
/*static void aff (struct liste *p_liste)
{
struct node const *p = p_liste->pTete;
while (p != NULL)
{
struct data const *p_data = &p->data;
printf ("[%d] %d %d %d %d %d\n ", p_data->Indice, p_data->Combi[0],
p_data->Combi[1], p_data->Combi[2], p_data->Combi[3],
p_data->Combi[4]);
p = p->psuiv;
}
}*/
static void scan_N (struct liste *p_liste, struct data *p_data)
{
struct node const *p = p_liste->pTete;
int i=0;
while (p != NULL)
{
int Compteur=0;
for (i=0; i<5; i++)
{
if (p->data.Combi[i]==p_data->Combi[i]) {Compteur++;}
}
printf("%d\n", Compteur);
if ( ( Compteur > 0 ) && ( Compteur < 5 ) )
{p_data->N[Compteur]=p_data->N[Compteur]+1;
}
p = p->psuiv;
}
}
static void analyse (struct liste *p_liste)
{
struct node const *p = p_liste->pTete;
while (p != NULL)
{
struct data *p_data = &p->data;
scan_N(p_liste, p_data);
p = p->psuiv;
}
}
int main (void)
{
struct liste liste = { NULL, NULL };
Filtrage ();
LoadCombi (&liste);
printf ("Done !!!\n\n");
/*aff (&liste);*/
analyse (&liste);
return 0;
} |
Partager