Program to construct a DFA which accepts the language L = { aN | N â ‰¥ 1 } | C ++ program for the above approach ; Function to check whether the string S satisfy the given DFA or not ; Stores the count of characters ; Iterate over the range [ 0 , N ] ; Count and check every element for ' a ' ; If string matches with DFA ; If not matches ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void isAcceptedDFA ( string s , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s [ i ] == ' a ' ) count ++ ; } if ( count == N && count != 0 ) { cout << " Accepted " ; } else { cout << " Not ▁ Accepted " ; } } int main ( ) { string S = " aaaaa " ; isAcceptedDFA ( S , S . size ( ) ) ; return 0 ; }