Result chart
1 # include <stdio. h> 2 // s is the initial state, and z is the final state. 3 int in (int s, int z) 4 {5 if (s = z) 6 {7 printf ("3 \ nlook! The last status belongs to Z "); 8 return 1; 9} 10 else11 {12 return 0; 13} 14} 15 // s is in the status, t is the input character 16 int step (int s, char t) 17 {18 if (t = 'A') 19 switch (s) 20 {21 case 0: return 1; 22 case 1: return 3; 23 case 2: return 1; 24 case 3: return 3; 25} 26 else if (t = 'B ') 27 switch (s) 28 {29 case 0: return 2; 30 case 1: return 2; 31 case 2: return 3; 32 case 3: return 3; 33} 34} 35 36 int realize (char * input) 37 {38 int z = 3; 39 int s, I; 40 s = 0; 41 for (I = 0; input [I]! = '\ N'; I ++) 42 {43 printf ("% 2d", s); 44 s = step (s, input [I]); 45} 46 if (in (s, z) 47 {48 return 1; 49} 50 else51 {52 return 0; 53} 54} 55 56 main () 57 {58 int I; 59 int a; 60 char input [40]; 61 printf ("FA = ({0, 1, 2, 3}, {a, B}, M, 0, {3}) \ n "); 62 printf (" M: \ n "); 63 printf (" M (0, a) = 1 M (0, B) = 2 \ n "); 64 printf (" M (1, a) = 3 M (1, B) = 2 \ n "); 65 printf (" M (2, a) = 1 M (2, B) = 3 \ n "); 66 printf (" M (3, a) = 3 M (3, B) = 3 \ n "); 67 printf (" Enter the string you want to check "); 68 69 lop: for (I = 0; input [I-1]! = '\ N'; I ++) 70 {71 scanf ("% c", & input [I]); 72} 73 for (I = 0; input [I-1]! = '\ N'; I ++) 74 {75 if (input [I]! = 'A' & input [I]! = 'B' & input [I]! = '\ N') 76 {77 printf ("input error, enter again please: \ n"); 78 goto lop; 79} 80 81} 82 printf ("the status sequence is: \ n"); 83 a = realize (input); 84 if (a = 1) 85 printf ("\ nSo this string can be identified \ n"); 86 else87 printf ("\ nSo this string can't be identified \ n "); 88 printf ("press enter to exit the program \ n"); 89 getchar (); 90 91}