Advertisement
Guest User

HEHEEEBOIII

a guest
Nov 20th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.74 KB | None | 0 0
  1. //matrice:
  2.  
  3. int** setMatrice(FILE* f,int nbl, int nbc){
  4.     int **M;
  5.     M=(int**)malloc(nbc*sizeof(int*));
  6.     for(int i=0;i<nbl;i++)
  7.         M[i]=(int*)malloc(nbl*sizeof(int));
  8.     for(int i=0;i<nbc;i++){
  9.         for(int j=0;j<nbl;j++){
  10.             fscanf(f,"%d",&M[i][j]);
  11.         }
  12.     }
  13.     return M;
  14. }
  15.  
  16. //l matrice f FILE f,
  17. //#############################
  18.  
  19. le mot ( !pour € {a,b,c} )
  20.  
  21. struct mot{
  22.     int *tab;
  23.     int taille_mot;
  24. };
  25.  
  26. struct mot mot(char *tab){
  27.     struct mot T;
  28.     T.taille_mot=strlen(tab);
  29.     T.tab=(int*)malloc(T.taille_mot*sizeof(int));
  30.     for(int i=0;i<T.taille_mot;i++){
  31.         T.tab[i]=tab[i]-'a';
  32.     }
  33.     return T;
  34. }
  35.  
  36. //############################
  37.  
  38. int trace(int** M, int ETAT_INIT, int* mot, int taille_mot){
  39.     int resultat=ETAT_INIT;
  40.     for(int i=0 ; i<taille_mot && resultat!=-1 ; i++){
  41.         resultat=M[resultat][mot[i]];
  42.     }
  43.     return resultat;
  44. }
  45.  
  46. //############################
  47.  
  48. bool reconaissance(int resultat, int etatFinale){
  49.     if(resultat==etatFinale)
  50.         return true; //mot n'existe pas
  51.     else
  52.         return false; //mot existe
  53. }
  54.  
  55. //#############################
  56.  
  57. int main(){
  58.     int **M;
  59.     FILE* f;
  60.     char *tab;
  61.     struct mot Mot;
  62.     int ETAT_FINALE;
  63.     int ETAT_INIT;
  64.     scanf("%d%d", &ETAT_FINALE, &ETATINIT);
  65.     f=fopen("mat.txt","r");
  66.     fscanf(f,"%d",&nbc); //supposant que le nbr des cols se trouve dans la 1ere ligne
  67.     fscanf(f,"%d",&nbl); //....2eme
  68.     M=setMatrice(f,nbl,nbc);
  69.     fclose(f);
  70.     f=fopen("mot.txt", "r");
  71.     while(!feof(f)){
  72.         fscanf(f,"%s",tab);
  73.         printf("%s", tab);
  74.         Mot=setMot(tab);
  75.         if(reconnaissance(trace(M, int ETAT_INIT, Mot.tab, Mot.taille_mot), ETAT_FINALE))
  76.             printf("mot existe");
  77.         else
  78.             printf("mot n'existe pas");
  79.         printf("\n");
  80.     }
  81.     fclose(f);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement