Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //matrice:
- int** setMatrice(FILE* f,int nbl, int nbc){
- int **M;
- M=(int**)malloc(nbc*sizeof(int*));
- for(int i=0;i<nbl;i++)
- M[i]=(int*)malloc(nbl*sizeof(int));
- for(int i=0;i<nbc;i++){
- for(int j=0;j<nbl;j++){
- fscanf(f,"%d",&M[i][j]);
- }
- }
- return M;
- }
- //l matrice f FILE f,
- //#############################
- le mot ( !pour € {a,b,c} )
- struct mot{
- int *tab;
- int taille_mot;
- };
- struct mot mot(char *tab){
- struct mot T;
- T.taille_mot=strlen(tab);
- T.tab=(int*)malloc(T.taille_mot*sizeof(int));
- for(int i=0;i<T.taille_mot;i++){
- T.tab[i]=tab[i]-'a';
- }
- return T;
- }
- //############################
- int trace(int** M, int ETAT_INIT, int* mot, int taille_mot){
- int resultat=ETAT_INIT;
- for(int i=0 ; i<taille_mot && resultat!=-1 ; i++){
- resultat=M[resultat][mot[i]];
- }
- return resultat;
- }
- //############################
- bool reconaissance(int resultat, int etatFinale){
- if(resultat==etatFinale)
- return true; //mot n'existe pas
- else
- return false; //mot existe
- }
- //#############################
- int main(){
- int **M;
- FILE* f;
- char *tab;
- struct mot Mot;
- int ETAT_FINALE;
- int ETAT_INIT;
- scanf("%d%d", &ETAT_FINALE, &ETATINIT);
- f=fopen("mat.txt","r");
- fscanf(f,"%d",&nbc); //supposant que le nbr des cols se trouve dans la 1ere ligne
- fscanf(f,"%d",&nbl); //....2eme
- M=setMatrice(f,nbl,nbc);
- fclose(f);
- f=fopen("mot.txt", "r");
- while(!feof(f)){
- fscanf(f,"%s",tab);
- printf("%s", tab);
- Mot=setMot(tab);
- if(reconnaissance(trace(M, int ETAT_INIT, Mot.tab, Mot.taille_mot), ETAT_FINALE))
- printf("mot existe");
- else
- printf("mot n'existe pas");
- printf("\n");
- }
- fclose(f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement