Untitled
unknown
c_cpp
a year ago
788 B
3
Indexable
#include <stdio.h> // Function to simulate the DFA for string acceptance int dfa(char str[]) { int currentState = 0; // Starting state is q0 for (int i = 0; str[i] != '\0'; i++) { char input = str[i]; switch (currentState) { case 0: if (input == 'a') currentState = 1; break; case 1: if (input == 'b') currentState = 0; else if (input == 'a') currentState = 1; break; } } // Check if the final state is q0 return currentState == 0; } int main() { char inputString[] = "ababbb"; if (dfa(inputString)) printf("String accepted by the DFA\n"); else printf("String not accepted by the DFA\n"); return 0; }
Editor is loading...
Leave a Comment