Bonsoir la communauté,
J'ai rédigé ce programme et j'ai besoin de mettre ça en algo.
Quelqu'un pourrait m'aider svp !

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
typedef struct
{
char nom[4];
int nombre;
} Codon;
 
void ExtractFirstCodon(char codon[], char chaine[])
{
strncpy(codon, chaine, 3);
codon[3] = '\0';
}
 
void InsertCodon(Codon listCodon[], char codon[], int position)
{
listCodon[position].nombre=1;
strcpy(listCodon[position].nom, codon);
}
 
int CompteCodons(char chaine[], Codon listCodon[])
{
int nb_codon = strlen(chaine)-2;
char codon[4];
int indiceCodon = 1;
 
for(int i=0; i<nb_codon; i++)
{
ExtractFirstCodon(codon, chaine);
if(i==0)
{
InsertCodon(listCodon, codon, 0);
chaine++;
continue;
}
 
int codonAbsent = 1;
 
for(int j=0; j<i; j++)
{
if(strcmp(listCodon[j].nom, codon)==0)
{
listCodon[j].nombre++;
codonAbsent=0;
}
}
 
if(codonAbsent)
{
InsertCodon(listCodon, codon, indiceCodon);
indiceCodon++;
}
 
chaine++;
}
return indiceCodon;
}
int Tri_occ(const void *cd1, const void *cd2)
{
int compar= ((Codon*)cd1)->nombre - ((Codon*)cd2)->nombre;
if (compar==0)
{
return strcmp(((Codon*)cd1)->nom , ((Codon*)cd2)->nom) ;
}
else
return -compar;
}
 
 
 
int main(void)
{
char chaine [100] = "TACGACGCGACTACGTCGTACG";
Codon listCodon[64];
 
int nbCodon = CompteCodons(chaine, listCodon);
qsort(listCodon, nbCodon, sizeof(Codon), Tri_occ);
for(int i=0; i<nbCodon; i++)
printf("%s --> %d\n", listCodon[i].nom, listCodon[i].nombre);
 
return 0;
}