Untitled
unknown
plain_text
a year ago
1.0 kB
4
Indexable
#include <stdio.h> #include <string.h> // DFA Transition function int transition(int state, char input) { switch (state) { case 0: return (input == 'a') ? 1 : 0; case 1: return (input == 'b') ? 2 : 0; case 2: return 2; // Accepting state default: return 0; // Invalid state } } // DFA String acceptance check function int isAccepted(char *input) { int currentState = 0; int len = strlen(input); int i; for (i = 0; i < len; i++) { currentState = transition(currentState, input[i]); } return (currentState == 2); // Check if the final state is accepting (2) } int main() { char input[100]; // Input from the user printf("Enter a string: "); scanf("%s", input); // Check if the input string is accepted if (isAccepted(input)) { printf("Accepted\n"); } else { printf("Not Accepted\n"); } return 0; }
Editor is loading...
Leave a Comment