Chiedo venia. Mancano alcune transizioni nella versione che ho postato prima.
Questa è la versione corretta:
codice:#include <stdio.h> #include <ctype.h> #include <conio.h> typedef enum tagStati { S0, S1, S2, S3, S4, S5, S6, S7, S8 } Stati; void Automa() { Stati stato = S0; int c = 0; while ( c != 'X' ) { //c = toupper(getch()); c = toupper(_getch()); if ( c == 'X' ) { printf("digitato X\n"); break; } else if ( c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E' ) { printf("digitato %c\n", c); } switch(stato) { case S0: if ( c == 'C' ) stato = S1; else if ( c == 'B' ) stato = S5; break; case S1: if ( c == 'A' ) stato = S2; else if ( c == 'B' ) stato = S5; else if ( c == 'D' || c == 'E' ) stato = S0; break; case S2: if ( c == 'B' ) stato = S3; else if ( c == 'C' ) stato = S1; else if ( c == 'A' || c == 'D' || c == 'E' ) stato = S0; break; case S3: if ( c == 'E' ) stato = S4; else if ( c == 'A' ) stato = S6; else if ( c == 'C' ) stato = S1; else if ( c == 'B' ) stato = S5; else if ( c == 'D' ) stato = S6; break; case S4: if ( c == 'D' ) { printf("Fermi tutti!!! CABED riconosciuta!\n"); stato = S0; } else if ( c == 'C' ) stato = S1; else if ( c == 'B' ) stato = S5; else if ( c == 'A' || c == 'E' ) stato = S0; break; case S5: if ( c == 'A' ) stato = S6; else if ( c == 'C' ) stato = S1; else if ( c == 'D' || c == 'E' ) stato = S0; break; case S6: if ( c == 'B' ) stato = S7; else if ( c == 'C' ) stato = S1; else if ( c == 'A' || c == 'D' || c == 'E' ) stato = S0; break; case S7: if ( c == 'A' ) stato = S8; else if ( c == 'C' ) stato = S1; else if ( c == 'B' ) stato = S5; else if ( c == 'D' || c == 'E' ) stato = S0; break; case S8: if ( c == 'B' ) { printf("Fermi tutti!!! BABAB riconosciuta!\n"); stato = S5; } else if ( c == 'C' ) stato = S1; else if ( c == 'A' || c == 'D' || c == 'E' ) stato = S0; break; } } } int main() { Automa(); return 0; }

Rispondi quotando