Convert dfa in C++ / C plus plus to check whether a string contains nano or not
In this program i have converted a DFA into c++ / C Plus Plus program that checks weather a string contains "nano" or not. Program is written below
#include#include using namespace std; int main() { int state = 0; char c; cout << "Press \'.\' to terminate program." << endl; while(c != '.') { c = getche(); switch(state) { case 0: { if(c=='n') state=1; else state=0; break; } case 1: { if(c=='a') state=2; else if(c=='n') state=1; break; } case 2: { if(c=='n') state=3; else if(c=='a') state=0; break; } case 3: { if(c=='o') state=4; else if(c=='n') state=1; else state=0; break; } case 4: { break; } } } if(state == 4) cout << endl << "nano is exits in this string." << endl; getch(); }
Convert dfa in C++ / C plus plus to check whether a string contains nano or not
Reviewed by Unknown
on
08:53
Rating: